Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > ImageIcon to Image in a jar file?

Reply
Thread Tools

ImageIcon to Image in a jar file?

 
 
tiewknvc9
Guest
Posts: n/a
 
      08-14-2006
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?

 
Reply With Quote
 
 
 
 
tiewknvc9
Guest
Posts: n/a
 
      08-14-2006
I tried this:

myImage = ImageIO.read(getClass().getResource(myImageIcon.to String()));

but it doesnt work because the toString method breaks in the jars
execution...



tiewknvc9 wrote:
> 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?


 
Reply With Quote
 
 
 
 
tiewknvc9
Guest
Posts: n/a
 
      08-14-2006
I also tried simply

myImage = myImageIcon.getImage();

but that causes a crash too...

tiewknvc9 wrote:
> 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?


 
Reply With Quote
 
danharrisandrews@gmail.com
Guest
Posts: n/a
 
      08-14-2006
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
- - - - - - - - - - - - - - - - - - - - - - - -



tiewknvc9 wrote:
> 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?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java -cp a.jar -jar b.jar => Works on Windows, not on Debian cyberco Java 4 02-14-2006 06:27 AM
jaas.jar, jta.jar jdbc-stdext.jar missing from jdk1.5 RPM muttley Java 0 10-20-2005 02:40 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters Java 0 01-05-2005 10:59 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters XML 0 01-05-2005 10:59 PM
JTable ImageIcon terry Java 2 08-06-2003 06:09 AM



Advertisments