• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Load images from JAR file

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I was wondering if there is an easy way to load images from a JAR file?

For example if the images are located in the following package:

com/foo/images

Inside images there are say 20 images, but there could be more.

How can I loop through these images in an easy way?
 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Apparently its possible to load images that are contained within a JAR, but I could never get it to work, so I came up with my own solution:

Basically load the pic in the normal way, then scan it to get the pixel data. You then save this, so you can generate BufferedImages at runtime from the pixel data.

Drawback is, this is probably only a good idea for small pics, such as chess pieces (50 by 50 pngs in my case).

Another possibility is to save a text file in the jar with the same pixel data, and then do the same thing.

But I'm sure the people here can show you the proper way to do it with images in jars.
 
Henrik Engert
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am able to load one image at a time IF I know the image name, which comes from a database. But I would like to load them all once and for all.

I would like to load the images just like you list what files are in a directory, but these are in a JAR file....

Anybody else have an idea?
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at the class JarFile in java.util.jar
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As keith mentioned take a look at the util.jar specifically the JarFile Class and use the getEnteries() to get an enumeration of all the files in the jar. You can then iterate thru the enumeration to see if any of them are images and then load them. Hope this helps

- Harjit
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic