ui/src/main/java/ucar/nc2/ui/image/ScalablePicture.java
public static void writeJpg(File writeFile, RenderedImage renderedImage, float jpgQuality) {
    Iterator writers = ImageIO.getImageWritersByFormatName("jpg");
    ImageWriter writer = (ImageWriter) writers.next();
    JPEGImageWriteParam params = new JPEGImageWriteParam(null);
    params.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    params.setCompressionQuality(jpgQuality);
    params.setProgressiveMode(ImageWriteParam.MODE_DISABLED);
    params.setDestinationType(new ImageTypeSpecifier(java.awt.image.IndexColorModel.getRGBdefault(),
        IndexColorModel.getRGBdefault().createCompatibleSampleModel(16, 16)));

    try(ImageOutputStream ios = ImageIO.createImageOutputStream(new FileOutputStream(writeFile))) {
      writer.setOutput(ios);
      writer.write(null, new IIOImage(renderedImage, null, null), params);
      ios.close();
    } catch (IOException e) {
      //Tools.log("ScalablePicture.writeJpg caught IOException: " +  e.getMessage() + "\nwhile writing " + writeFile.toString());
      e.printStackTrace();
    }
    //writer = null;
    writer.dispose(); //1.4.1 documentation says to do this.
  }
public static void writeJpg(File writeFile, RenderedImage renderedImage, float jpgQuality) {
    Iterator writers = ImageIO.getImageWritersByFormatName("jpg");
    ImageWriter writer = (ImageWriter) writers.next();
    JPEGImageWriteParam params = new JPEGImageWriteParam(null);
    params.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    params.setCompressionQuality(jpgQuality);
    params.setProgressiveMode(ImageWriteParam.MODE_DISABLED);
    params.setDestinationType(new ImageTypeSpecifier(java.awt.image.IndexColorModel.getRGBdefault(),
        IndexColorModel.getRGBdefault().createCompatibleSampleModel(16, 16)));

    try(ImageOutputStream ios = ImageIO.createImageOutputStream(new FileOutputStream(writeFile))) {
      writer.setOutput(ios);
      writer.write(null, new IIOImage(renderedImage, null, null), params);
      ios.close();
    } catch (IOException e) {
      //Tools.log("ScalablePicture.writeJpg caught IOException: " +  e.getMessage() + "\nwhile writing " + writeFile.toString());
      e.printStackTrace();
    }
    //writer = null;
    writer.dispose(); //1.4.1 documentation says to do this.
  }
public static void writeJpg ( File writeFile , RenderedImage renderedImage , float jpgQuality ) { Iterator writers = ImageIO . getImageWritersByFormatName ( "jpg" ) ; ImageWriter writer = ( ImageWriter ) writers . next ( ) ; JPEGImageWriteParam params = new JPEGImageWriteParam ( null ) ; params . setCompressionMode ( ImageWriteParam . MODE_EXPLICIT ) ; params . setCompressionQuality ( jpgQuality ) ; params . setProgressiveMode ( ImageWriteParam . MODE_DISABLED ) ; params . setDestinationType ( new ImageTypeSpecifier ( java . awt . image . IndexColorModel . getRGBdefault ( ) , IndexColorModel . getRGBdefault ( ) . createCompatibleSampleModel ( 16 , 16 ) ) ) ; try ( ImageOutputStream ios = ImageIO . createImageOutputStream ( new FileOutputStream ( writeFile ) ) ) { writer . setOutput ( ios ) ; writer . write ( null , new IIOImage ( renderedImage , null , null ) , params ) ; ios . close ( ) ; } catch ( IOException e ) { //Tools.log("ScalablePicture.writeJpg caught IOException: " +  e.getMessage() + "\nwhile writing " + writeFile.toString());
 e . printStackTrace ( ) ; } //writer = null;
 writer . dispose ( ) ; //1.4.1 documentation says to do this.
 }
This static method writes the indicated renderedImage (BufferedImage)
to the indicated file.

@param  writeFile  The File that shall receive the jpg data
@param  renderedImage  The RenderedImage (BufferedImage) to be written
@param  jpgQuality  The quality with which to compress to jpg
This static method writes the indicated renderedImage ( BufferedImage ) to the indicated file .