Login  Register

Re: How to save an image in different formats

Posted by Herbie on Apr 26, 2016; 5:45pm
URL: http://imagej.273.s1.nabble.com/How-to-save-an-image-in-different-formats-tp5016229p5016241.html

OK Daniel,

my previous code snippet does what you want but without the drop-down menu.
Here is a polished version:

//
newImage( "Example", "8-bit random", 128, 128, 1 );
items = newArray( "TIFF","JPEG","PNG" );
Dialog.create( "Save Image" );
Dialog.addChoice( "Format:", items, items[0] );
Dialog.show();
format = Dialog.getChoice();
saveAs( format );
run( "Close" );
//

HTH

Herbie

:::::::::::::::::::::::::::::::::::::::::::::::::::::::
What i mean is like in this picture

figure images/SaveAsImageSequence.png


I want to have posibility to choose what format to save.


On Tuesday, April 26, 2016 7:59 PM, Herbie <[hidden email]> wrote:


Daniel,

is this (example) macro

//
newImage("Example", "8-bit random", 128, 128, 1);
format = getString("Please enter either 'tiff',  'jpeg', or 'png'
without quotation marks.", "tiff");
saveAs(format);
run("Close");
//

what you are looking for?
Open an empty macro text window (Plugins > New > Macro) and copy the
above to it and run...

Best

Herbie

::::::::::::::::::::::::::::::::::::::::::
Am 26.04.16 um 17:35 schrieb sabau daniel:
 > Hello,I'm new in imagej, and i want to make a field/label with an
 > option to save an image in jpg,tiff,jpeg .How to do that,how to
 > implement in the following code.Thanks. import java.io.File;
 >
 > import ij.IJ;
 >
 > import ij.ImagePlus;
 >
 > import ij.plugin.PlugIn;
 >
 > importij.process.ImageProcessor;
 >
 >
 >
 > //This plugin shows the basicstructure of a code.
 >
 > public class Open_Image implements PlugIn {
 >
 > public void run(String arg) { //Method Belongingto PlugIn
 > Implementation
 >
 >
 >
 > StringmyDirector1 = IJ.getDirectory("Select SourceFolder...");
 > //This pluginopens the select folder window in ImageJ
 >
 > if (myDirector1==null) return;
 > //If not sourcefolder is selected the plugin stops here
 >
 > String[]myListSources = new File(myDirector1).list();
 > //This string contains all the filesnames in the source folder
 >
 > if (myListSources==null) return;
 >
 > IJ.log("The sourceimage folder chosen was"+myDirector1);
 > //This command opens the log window andwrites on the variables on
 > it.
 >
 >
 >
 > StringmyDirector2 = IJ.getDirectory("Select SavingFolder...");
 >
 > if (myDirector2==null) return;
 > //If not savingfolder is selected the plugin stops here
 >
 > IJ.log("The savingfolder chosen was"+myDirector2);
 >
 >
 >
 > int Image;
 >
 >
 >
 > for (Image = 0; Image < myListSources.length; Image++) {
 >
 >
 >
 > IJ.showProgress(Image,myListSources.length);
 > //This command sets magnitude the progressbar on ImageJ
 >
 > IJ.log((Image+1)+":"+myListSources[Image]);
 >
 > IJ.showStatus(Image+"/"+myListSources.length);
 > //This command sets a text in theImageJ status bar
 >
 >
 >
 > ImagePlusmyImPlus = IJ.openImage(myDirector1+myListSources[Image]);
 >
 > myImPlus.show();
 > //This commandopens a window with the corresponding ImagePlus
 >
 > ImageProcessormyIp = myImPlus.getProcessor();
 >
 > myImPlus.updateAndDraw();
 >
 >
 >
 >
 > IJ.log("Completed");
 >
 > }
 >
 > }
 >
 >
 > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html

 >

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

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