Login  Register

Re: Read/open image from resource inside a JAR file?

Posted by Michael Schmid on May 31, 2016; 3:52pm
URL: http://imagej.273.s1.nabble.com/Read-open-image-from-resource-inside-a-JAR-file-tp5016554p5016556.html

Hi Wilhelm,

a rough guess, stealing code from here and there...

If you have a plugin named MyPlugin, and a directory 'images' in its
.jar file, you can use
   URL imageURL = MyPlugin.class.getResource("images/myImage.png");

Then use the ImageJ URLOpener class or get a BufferedImage with
javax.imageio.ImageIO:
   BufferedImage bi = ImageIO.read(url);


Michael
________________________________________________________________
On 2016-05-31 16:22, Burger Wilhelm wrote:

> Hello group,
>
> does anyone know of a straightforward way to read/open an image that is contained as a resource inside a JAR file? That is, without perhaps copying an java.io.InputStream to a temporary file etc. ...
>
> Any hints highly appreciated
> -- Wilhelm
>
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html