Example usage for javax.imageio.plugins.jpeg JPEGImageWriteParam setDestinationType

List of usage examples for javax.imageio.plugins.jpeg JPEGImageWriteParam setDestinationType

Introduction

In this page you can find the example usage for javax.imageio.plugins.jpeg JPEGImageWriteParam setDestinationType.

Prototype

public void setDestinationType(ImageTypeSpecifier destinationType) 

Source Link

Document

Sets the desired image type for the destination image, using an ImageTypeSpecifier .

Usage

From source file:org.modelibra.util.ImageHandler.java

/**
 * Saves an image to a jpeg file./*from  w w  w .  j  av  a2  s  . c  o  m*/
 * 
 * @param bi
 *            buffered image
 * @param file
 *            jpeg file
 * @param quality
 *            image quality
 */
public static void saveImageToJPEGFile14(BufferedImage bi, File file, float quality) throws IOException {

    JPEGImageWriteParam param = new JPEGImageWriteParam(null);
    ImageTypeSpecifier type = new ImageTypeSpecifier(bi);
    param.setDestinationType(type);
    ImageOutputStream imgos = ImageIO.createImageOutputStream(file);
    Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpeg");
    ImageWriter writer = writers.next();
    writer.setOutput(imgos);
    writer.write(bi);
    imgos.close();
}