Login  Register

Jpeg Quality

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Jpeg Quality

Jon Harman
Hi,

I'd like to make a jpeg save dialog that shows the quality setting and allows the user to change it before saving (I would recommend this usage as the default for ImageJ).  I can see how to set it, but don't know how to get it.  It would also be nice if the quality number could be incorporated into the file save dialog, to reduce the number of clicks needed.  Here is a fragment of my code:

     double jpegqual = 75;
           
    GenericDialog gd1 = new GenericDialog("JPEG Quality, 100 is best");
    gd1.addNumericField("Quality (0-100)",jpegqual,0);
   
    gd1.showDialog();
    if(!gd1.wasCanceled()) {
     jpegqual = gd1.getNextNumber();
     IJ.run("Input/Output...", "jpeg=" + IJ.d2s(jpegqual));
     IJ.run("Jpeg...");
    }

Jon
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Jpeg Quality

Wayne Rasband
Here is a macro that allows the user to change the JPEG quality  
setting before saving. Add it to ImageJ/macros/StartupMacros.txt and  
you will be able to save in JPEG format by pressing "j". You will  
need to write a plugin that extends JFileChooser to show the setting  
in the save dialog.

   macro "Save As JPEG... [j]" {
      quality = call("ij.plugin.JpegWriter.getQuality");
      quality = getNumber("JPEG quality (0-100):", quality);
      run("Input/Output...", "jpeg="+quality);
      saveAs("Jpeg");
   }

-wayne

On Feb 19, 2007, at 6:08 PM, Jon Harman wrote:

> Hi,
>
> I'd like to make a jpeg save dialog that shows the quality setting  
> and allows the user to change it before saving (I would recommend  
> this usage as the default for ImageJ).  I can see how to set it,  
> but don't know how to get it.  It would also be nice if the quality  
> number could be incorporated into the file save dialog, to reduce  
> the number of clicks needed.  Here is a fragment of my code:
>
>      double jpegqual = 75;
>
>     GenericDialog gd1 = new GenericDialog("JPEG Quality, 100 is  
> best");
>     gd1.addNumericField("Quality (0-100)",jpegqual,0);
>
>     gd1.showDialog();
>     if(!gd1.wasCanceled()) {
>      jpegqual = gd1.getNextNumber();
>      IJ.run("Input/Output...", "jpeg=" + IJ.d2s(jpegqual));
>      IJ.run("Jpeg...");
>     }
>
> Jon