Example usage for org.apache.commons.imaging ImageFormats JPEG

List of usage examples for org.apache.commons.imaging ImageFormats JPEG

Introduction

In this page you can find the example usage for org.apache.commons.imaging ImageFormats JPEG.

Prototype

ImageFormats JPEG

To view the source code for org.apache.commons.imaging ImageFormats JPEG.

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;
    }/*from w ww .ja v a 2 s  .  c om*/

    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:org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageWriter.java

@Override
public void write(IIOMetadata iioMetadata, IIOImage iioImage, ImageWriteParam param) throws IOException {

    if (ios == null) {
        throw new IllegalArgumentException(Messages.getString("imageio.7F"));
    }/*from  w  w  w  . j a v  a2  s .co m*/

    RenderedImage img = null;
    if (!iioImage.hasRaster()) {
        img = iioImage.getRenderedImage();
        if (img instanceof BufferedImage) {
            sourceRaster = ((BufferedImage) img).getRaster();
        } else {
            sourceRaster = img.getData();
        }
    } else {
        sourceRaster = iioImage.getRaster();
    }

    Map params = new HashMap();
    try {

        Imaging.writeImage((BufferedImage) img, wrapOutput(ios), //(OutputStream)ios,
                ImageFormats.JPEG, params);
    } catch (ImageWriteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.github.jipsg.sanselan.BaseSanselanTest.java

private ImageFormat getImageFormat(String formatName) {

    if ("jpg".equalsIgnoreCase(formatName)) {
        return ImageFormats.JPEG;
    } else if ("jpeg".equalsIgnoreCase(formatName)) {
        return ImageFormats.JPEG;
    } else if ("png".equalsIgnoreCase(formatName)) {
        return ImageFormats.PNG;
    } else {// w  w  w . j  a  v a 2 s.  c o m
        throw new IllegalArgumentException("Don't know how to handle : " + formatName);
    }
}