1 | initial version |
For some reason, the returned resource path has a '/' prefix (I think I read somewhere this is a known Java bug).
I used this code to solve it:
String url1 = getClass().getResource("/resources/lena.png").getPath();
if (url1.startsWith("/", 0))
url1=url1.replaceFirst("/", "");
2 | No.2 Revision |
For some reason, the returned resource path has a '/' prefix (I think I read somewhere this is a known Java bug).bug). Plus, the code cannot handle %20 (space) in the url.
I used this code to solve it:
try{
String url1 = getClass().getResource("/resources/lena.png").getPath();
if (url1.startsWith("/", 0))
url1=url1.replaceFirst("/", "");
url1=URLDecoder.decode(url1, "UTF-8"); //this will replace %20 with spaces
Mat image = Highgui.imread(url1);
}
catch ...
3 | No.3 Revision |
For some reason, the returned resource path has a '/' prefix (I think I read somewhere this is a known Java bug). Plus, the code cannot handle %20 (space) in the url.
I used this code to solve it:
try{
String url1 = getClass().getResource("/resources/lena.png").getPath();
if (url1.startsWith("/", 0))
url1=url1.replaceFirst("/", "");
url1=URLDecoder.decode(url1, "UTF-8"); //this will replace %20 with spaces
Mat image = Highgui.imread(url1);
}
catch ...