Example usage for javax.imageio ImageWriteParam getCompressionType

List of usage examples for javax.imageio ImageWriteParam getCompressionType

Introduction

In this page you can find the example usage for javax.imageio ImageWriteParam getCompressionType.

Prototype

public String getCompressionType() 

Source Link

Document

Returns the currently set compression type, or null if none has been set.

Usage

From source file:org.dcm4che2.tool.dcm2jpg.Dcm2Jpg.java

private void encodeByImageIO(BufferedImage bi, File dest) throws IOException {
    ImageWriter writer = getImageWriter(imageWriterClassname);
    ImageOutputStream out = null;
    try {//from  www . j  av  a  2  s  . c o m
        out = ImageIO.createImageOutputStream(dest);
        writer.setOutput(out);
        ImageWriteParam iwparam = writer.getDefaultWriteParam();
        if (iwparam.canWriteCompressed()) {
            iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            String[] compressionTypes = iwparam.getCompressionTypes();
            if (compressionTypes != null && compressionTypes.length > 0) {
                if (compressionType != null || iwparam.getCompressionType() == null) {
                    for (int i = 0; i < compressionTypes.length; i++) {
                        if (compressionType == null
                                || compressionTypes[i].compareToIgnoreCase(compressionType) == 0) {
                            iwparam.setCompressionType(compressionTypes[i]);
                            break;
                        }
                    }
                }
            }
            if (imageQuality != null)
                iwparam.setCompressionQuality(imageQuality);
        } else if (imageQuality != null) {
            System.out.println("Selected Image Writer can not compress! imageQuality is ignored!");
        }
        writer.write(null, new IIOImage(bi, null, null), iwparam);
    } finally {
        CloseUtils.safeClose(out);
        writer.dispose();
    }
}