Dear all,
I would like to have a plugin packed into a jar file with a GenericDialog using the method "void addImage(ImagePlus image)" where the linked picture will as well be packed in the jar. And in order to know how to define the loaded image path, I found the following link: https://stackoverflow.com/questions/10875892/in-java-how-do-you-retrieve-ima ges-from-a-jar-file which helped me to finally write: GenericDialog gd = new GenericDialog(title); URL url = getClass().getResource("/image/undo.png"); ImagePlus icon = IJ.openImage(url.getPath()); if(icon != null) gd.addImage(icon); else IJ.log("" + url); And this code is working very well when I compile the plugin with all the files outside the jars. But if once compiled I pack all the files within a jar, it tries unsuccessfully to find the picture under the following link: My_plugin_path/my_plugin.jar!/image/undo.png What am I doing wrong here? Thanks a lot in advance for your lightings and have a nice week-end. My best regards, Philippe Philippe CARL Laboratoire de Bioimagerie et Pathologies UMR 7021 CNRS - Université de Strasbourg Faculté de Pharmacie 74 route du Rhin 67401 ILLKIRCH Tel : +33(0)3 68 85 41 84 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
> On Feb 15, 2019, at 10:25 AM, Philippe CARL <[hidden email]> wrote:
> > Dear all, > I would like to have a plugin packed into a jar file with a GenericDialog > using the method "void addImage(ImagePlus image)" where the linked picture > will as well be packed in the jar. There is an example plugin at https://imagej.nih.gov/ij/plugins/pcl-demo.html that demonstrates how to load images, text files and macros from a jar file. -wayne > And in order to know how to define the loaded image path, I found the > following link: > > https://stackoverflow.com/questions/10875892/in-java-how-do-you-retrieve-ima > ges-from-a-jar-file > which helped me to finally write: > > GenericDialog gd = new GenericDialog(title); > URL url = getClass().getResource("/image/undo.png"); > ImagePlus icon = IJ.openImage(url.getPath()); > if(icon != null) > gd.addImage(icon); > else > IJ.log("" + url); > > And this code is working very well when I compile the plugin with all the > files outside the jars. > But if once compiled I pack all the files within a jar, it tries > unsuccessfully to find the picture under the following link: > My_plugin_path/my_plugin.jar!/image/undo.png > What am I doing wrong here? > Thanks a lot in advance for your lightings and have a nice week-end. > My best regards, > Philippe -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Wayne,
Thanks a lot for your link. And I confirm that the method "void displayJpeg()" from the "JAR_Resources_Demo.java" file works as well for png pictures. Small detail, wouldn't you want to replace the following line in the code: new ImagePlus("San Francisco (JPEG)", image).show(); by ImagePlus imp = new ImagePlus("San Francisco (JPEG)", image); if (imp!=null) imp.show(); Not only this could be more clear for beginners, but also it would be more consistent with the code for the "void displayTiff()" method found below. Have a nice day, Philippe -----Message d'origine----- De : ImageJ Interest Group [mailto:[hidden email]] De la part de Wayne Rasband Envoyé : vendredi 15 février 2019 18:20 À : [hidden email] Objet : Re: Reading pictures within a jar file > On Feb 15, 2019, at 10:25 AM, Philippe CARL <[hidden email]> wrote: > > Dear all, > I would like to have a plugin packed into a jar file with a GenericDialog > using the method "void addImage(ImagePlus image)" where the linked picture > will as well be packed in the jar. There is an example plugin at https://imagej.nih.gov/ij/plugins/pcl-demo.html that demonstrates how to load images, text files and macros from a jar file. -wayne > And in order to know how to define the loaded image path, I found the > following link: > > https://stackoverflow.com/questions/10875892/in-java-how-do-you-retrieve-ima > ges-from-a-jar-file > which helped me to finally write: > > GenericDialog gd = new GenericDialog(title); > URL url = getClass().getResource("/image/undo.png"); > ImagePlus icon = IJ.openImage(url.getPath()); > if(icon != null) > gd.addImage(icon); > else > IJ.log("" + url); > > And this code is working very well when I compile the plugin with all the > files outside the jars. > But if once compiled I pack all the files within a jar, it tries > unsuccessfully to find the picture under the following link: > My_plugin_path/my_plugin.jar!/image/undo.png > What am I doing wrong here? > Thanks a lot in advance for your lightings and have a nice week-end. > My best regards, > Philippe -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |