hi!
I am trying to get an image from an Imageicon within a jar file.
Outside of the jar file this is pretty easy,
myImage = myImageIcon.getImage();
to get from a string to an image obviously we do the following
URL url = Image.class.getResource(strFile);
that is not what I am asking though...
My function receives an ImageIcon, and I have to convert it to an Image
within the jar file...
Any ideas?
tiewknvc9 - 14 Aug 2006 22:35 GMT
I tried this:
myImage = ImageIO.read(getClass().getResource(myImageIcon.toString()));
but it doesnt work because the toString method breaks in the jars
execution...
> hi!
>
[quoted text clipped - 12 lines]
>
> Any ideas?
tiewknvc9 - 14 Aug 2006 22:36 GMT
I also tried simply
myImage = myImageIcon.getImage();
but that causes a crash too...
> hi!
>
[quoted text clipped - 12 lines]
>
> Any ideas?
danharrisandrews@gmail.com - 14 Aug 2006 22:41 GMT
Hi,
I always use the resource for a jar or for files. First make sure that
you copy your image files to your compiled sources location and then
reference your images like this. Always reference your resources that
way if you are going to eventually distribute them in a jar and it will
save to time in the end.
String location = "my/package/for/images/myimage.gif";
ImageIcon icon = null;
URL iconURL = SomeClassInJar.class.getClassLoader().getResource(
location);
if (iconURL != null) {
icon = new ImageIcon(iconURL);
}
Better yet, centralize this code in an ImageUtilities class to save
more time.
Cheers,
Dan Andrews
- - - - - - - - - - - - - - - - - - - - - - - -
Ansir Development Limited www.ansir.ca
- - - - - - - - - - - - - - - - - - - - - - - -
> hi!
>
[quoted text clipped - 12 lines]
>
> Any ideas?