Example usage for org.apache.commons.imaging.formats.tiff.constants TiffConstants TIFF_COMPRESSION_LZW

List of usage examples for org.apache.commons.imaging.formats.tiff.constants TiffConstants TIFF_COMPRESSION_LZW

Introduction

In this page you can find the example usage for org.apache.commons.imaging.formats.tiff.constants TiffConstants TIFF_COMPRESSION_LZW.

Prototype

int TIFF_COMPRESSION_LZW

To view the source code for org.apache.commons.imaging.formats.tiff.constants TiffConstants TIFF_COMPRESSION_LZW.

Click Source Link

Usage

From source file:com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRenderListener.java

private byte[] processImage(byte[] imageBytes, List<Rectangle> areasToBeCleaned) {
    if (areasToBeCleaned.isEmpty()) {
        return imageBytes;
    }/*w w w .ja v a 2 s. c o  m*/

    try {
        BufferedImage image = Imaging.getBufferedImage(imageBytes);
        ImageInfo imageInfo = Imaging.getImageInfo(imageBytes);
        cleanImage(image, areasToBeCleaned);

        // Apache can only read JPEG, so we should use awt for writing in this format
        if (imageInfo.getFormat() == ImageFormats.JPEG) {
            return getJPGBytes(image);
        } else {
            Map<String, Object> params = new HashMap<String, Object>();

            if (imageInfo.getFormat() == ImageFormats.TIFF) {
                params.put(ImagingConstants.PARAM_KEY_COMPRESSION, TiffConstants.TIFF_COMPRESSION_LZW);
            }

            return Imaging.writeImageToBytes(image, imageInfo.getFormat(), params);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java

public static void writeTiff(BufferedImage img, int compression, File file) throws IOException {
    if (img == null) {
        return;/*  ww w  .  ja  va 2 s  .c o  m*/
    }
    final ImageFormat format = ImageFormats.TIFF;
    final Map<String, Object> params = new HashMap<String, Object>();

    switch (compression) {
    case TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED:
    case TiffConstants.TIFF_COMPRESSION_CCITT_1D:
    case TiffConstants.TIFF_COMPRESSION_CCITT_GROUP_3:
    case TiffConstants.TIFF_COMPRESSION_CCITT_GROUP_4:
    case TiffConstants.TIFF_COMPRESSION_LZW:
    case TiffConstants.TIFF_COMPRESSION_PACKBITS:
        //case TiffConstants.TIFF_COMPRESSION_JPEG:
        break;
    default:
        compression = TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED;
    }
    ;

    params.put(ImagingConstants.PARAM_KEY_COMPRESSION, new Integer(compression));

    try {
        Imaging.writeImage(img, file, format, params);
    } catch (ImageWriteException ex) {
        throw new IOException(ex);
    }
}