• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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
 
This tiny ad is suggesting that maybe she should go play in traffic.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic