Example usage for org.apache.commons.imaging Imaging getICCProfile

List of usage examples for org.apache.commons.imaging Imaging getICCProfile

Introduction

In this page you can find the example usage for org.apache.commons.imaging Imaging getICCProfile.

Prototype

public static ICC_Profile getICCProfile(final File file) throws ImageReadException, IOException 

Source Link

Document

Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.

Usage

From source file:org.apache.commons.imaging.examples.SampleUsage.java

@SuppressWarnings("unused")
public SampleUsage() {

    try {/*from  w w w  .j  av  a  2s. c  om*/
        // <b>Code won't work unless these variables are properly
        // initialized.
        // Imaging works equally well with File, byte array or InputStream
        // inputs.</b>
        final BufferedImage someImage = null;
        final byte someBytes[] = null;
        final File someFile = null;
        final InputStream someInputStream = null;
        final OutputStream someOutputStream = null;

        // <b>The Imaging class provides a simple interface to the library.
        // </b>

        // <b>how to read an image: </b>
        final byte imageBytes[] = someBytes;
        final BufferedImage image_1 = Imaging.getBufferedImage(imageBytes);

        // <b>methods of Imaging usually accept files, byte arrays, or
        // inputstreams as arguments. </b>
        final BufferedImage image_2 = Imaging.getBufferedImage(imageBytes);
        final File file = someFile;
        final BufferedImage image_3 = Imaging.getBufferedImage(file);
        final InputStream is = someInputStream;
        final BufferedImage image_4 = Imaging.getBufferedImage(is);

        // <b>Write an image. </b>
        final BufferedImage image = someImage;
        final File dst = someFile;
        final ImageFormat format = ImageFormats.PNG;
        final Map<String, Object> optionalParams = new HashMap<>();
        Imaging.writeImage(image, dst, format, optionalParams);

        final OutputStream os = someOutputStream;
        Imaging.writeImage(image, os, format, optionalParams);

        // <b>get the image's embedded ICC Profile, if it has one. </b>
        final byte iccProfileBytes[] = Imaging.getICCProfileBytes(imageBytes);

        final ICC_Profile iccProfile = Imaging.getICCProfile(imageBytes);

        // <b>get the image's width and height. </b>
        final Dimension d = Imaging.getImageSize(imageBytes);

        // <b>get all of the image's info (ie. bits per pixel, size,
        // transparency, etc.) </b>
        final ImageInfo imageInfo = Imaging.getImageInfo(imageBytes);

        if (imageInfo.getColorType() == ImageInfo.ColorType.GRAYSCALE) {
            System.out.println("Grayscale image.");
        }
        if (imageInfo.getHeight() > 1000) {
            System.out.println("Large image.");
        }

        // <b>try to guess the image's format. </b>
        final ImageFormat imageFormat = Imaging.guessFormat(imageBytes);
        imageFormat.equals(ImageFormats.PNG);

        // <b>get all metadata stored in EXIF format (ie. from JPEG or
        // TIFF). </b>
        final ImageMetadata metadata = Imaging.getMetadata(imageBytes);

        // <b>print a dump of information about an image to stdout. </b>
        Imaging.dumpImageFile(imageBytes);

        // <b>get a summary of format errors. </b>
        final FormatCompliance formatCompliance = Imaging.getFormatCompliance(imageBytes);

    } catch (final Exception e) {

    }
}

From source file:org.gmdev.pdftrick.utils.CustomExtraImgReader.java

/**
 * Read a JPG image with CMYK ICC profile
 * @param imageByteArray/* w ww  .  j a  v  a2  s . c  om*/
 * @return The BufferedImage obj
 * @throws IOException
 * @throws ImageReadException
 */
public static BufferedImage readCMYK_JPG(byte[] imageByteArray) throws IOException, ImageReadException {

    colorType = COLOR_TYPE_RGB;
    hasAdobeMarker = false;

    InputStream in = new ByteArrayInputStream(imageByteArray);
    ImageInputStream stream = ImageIO.createImageInputStream(in);
    Iterator<ImageReader> iter = ImageIO.getImageReaders(stream);

    ImageReader reader = iter.next();
    reader.setInput(stream);

    BufferedImage image = null;
    ICC_Profile profile = null;

    colorType = COLOR_TYPE_CMYK;
    checkAdobeMarker(imageByteArray);
    profile = Imaging.getICCProfile(imageByteArray);

    WritableRaster raster = (WritableRaster) reader.readRaster(0, null);

    if (colorType == COLOR_TYPE_YCCK) {
        convertYcckToCmyk(raster);
    }
    if (hasAdobeMarker) {
        //convertInvertedColors(raster);
    }
    image = convertCmykToRgb(raster, profile);

    in.close();
    reader.dispose();
    return image;
}

From source file:org.imaging.CommonsImagingVariousExamples.java

public CommonsImagingVariousExamples() {

    try {//from w w  w.  java  2 s.c  o  m
        // <b>Code won't work unless these variables are properly
        // initialized.
        // Imaging works equally well with File, byte array or InputStream
        // inputs.</b>
        final BufferedImage someImage = null;
        final byte someBytes[] = null;
        final File someFile = null;
        final InputStream someInputStream = null;
        final OutputStream someOutputStream = null;

        // <b>The Imaging class provides a simple interface to the library.
        // </b>

        // <b>how to read an image: </b>
        final byte imageBytes[] = someBytes;
        final BufferedImage image_1 = Imaging.getBufferedImage(imageBytes);

        // <b>methods of Imaging usually accept files, byte arrays, or
        // inputstreams as arguments. </b>
        final BufferedImage image_2 = Imaging.getBufferedImage(imageBytes);
        final File file = someFile;
        final BufferedImage image_3 = Imaging.getBufferedImage(file);
        final InputStream is = someInputStream;
        final BufferedImage image_4 = Imaging.getBufferedImage(is);

        // <b>Write an image. </b>
        final BufferedImage image = someImage;
        final File dst = someFile;
        final ImageFormat format = ImageFormats.PNG;
        final Map<String, Object> optionalParams = new HashMap<String, Object>();
        Imaging.writeImage(image, dst, format, optionalParams);

        final OutputStream os = someOutputStream;
        Imaging.writeImage(image, os, format, optionalParams);

        // <b>get the image's embedded ICC Profile, if it has one. </b>
        final byte iccProfileBytes[] = Imaging.getICCProfileBytes(imageBytes);

        final ICC_Profile iccProfile = Imaging.getICCProfile(imageBytes);

        // <b>get the image's width and height. </b>
        final Dimension d = Imaging.getImageSize(imageBytes);

        // <b>get all of the image's info (ie. bits per pixel, size,
        // transparency, etc.) </b>
        final ImageInfo imageInfo = Imaging.getImageInfo(imageBytes);

        if (imageInfo.getColorType() == ImageInfo.ColorType.GRAYSCALE) {
            System.out.println("Grayscale image.");
        }
        if (imageInfo.getHeight() > 1000) {
            System.out.println("Large image.");
        }

        // <b>try to guess the image's format. </b>
        final ImageFormat imageFormat = Imaging.guessFormat(imageBytes);
        imageFormat.equals(ImageFormats.PNG);

        // <b>get all metadata stored in EXIF format (ie. from JPEG or
        // TIFF). </b>
        final ImageMetadata metadata = Imaging.getMetadata(imageBytes);

        // <b>print a dump of information about an image to stdout. </b>
        Imaging.dumpImageFile(imageBytes);

        // <b>get a summary of format errors. </b>
        final FormatCompliance formatCompliance = Imaging.getFormatCompliance(imageBytes);

    } catch (final Exception e) {
        e.printStackTrace();
    }
}