Java Code Examples for javax.imageio.metadata.IIOMetadata

The following examples show how to use javax.imageio.metadata.IIOMetadata. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: openjdk-jdk8u   Source File: ITXtTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static ITXtTest readFrom(File f) {
    try {
        ImageInputStream iis = ImageIO.createImageInputStream(f);
        ImageReader r = ImageIO.getImageReaders(iis).next();
        r.setInput(iis);

        IIOImage dst = r.readAll(0, null);

        // look for iTXt node
        IIOMetadata m = dst.getMetadata();
        Node root = m.getAsTree(m.getNativeMetadataFormatName());
        Node n = root.getFirstChild();
        while (n != null && !"iTXt".equals(n.getNodeName())) {
            n = n.getNextSibling();
        }
        if (n == null) {
            throw new RuntimeException("No iTXt node!");
        }
        ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n);
        return t;
    } catch (Throwable e) {
        throw new RuntimeException("Reading test failed.", e);
    }
}
 
Example 2
Source Project: jdk8u60   Source File: JPEGImageReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
public IIOMetadata getImageMetadata(int imageIndex)
    throws IOException {
    setThreadLock();
    try {
        // imageMetadataIndex will always be either a valid index or
        // -1, in which case imageMetadata will not be null.
        // So we can leave checking imageIndex for gotoImage.
        if ((imageMetadataIndex == imageIndex)
            && (imageMetadata != null)) {
            return imageMetadata;
        }

        cbLock.check();

        gotoImage(imageIndex);

        imageMetadata = new JPEGMetadata(false, false, iis, this);

        imageMetadataIndex = imageIndex;

        return imageMetadata;
    } finally {
        clearThreadLock();
    }
}
 
Example 3
private IIOMetadata upgradeMetadata(IIOMetadata src, BufferedImage bi) {
    String format = src.getNativeMetadataFormatName();
    System.out.println("Native format: " + format);
    Node root = src.getAsTree(format);

    // add hIST node
    Node n = lookupChildNode(root, "hIST");
    if (n == null) {
        System.out.println("Appending new hIST node...");
        Node hIST = gethISTNode(bi);
        root.appendChild(hIST);
    }

    System.out.println("Upgraded metadata tree:");
    dump(root, "");

    System.out.println("Merging metadata...");
    try {
        src.mergeTree(format, root);
    } catch (IIOInvalidTreeException e) {
        throw new RuntimeException("Test FAILED!", e);
    }
    return src;
}
 
Example 4
Source Project: TencentKona-8   Source File: ITXtTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static ITXtTest readFrom(File f) {
    try {
        ImageInputStream iis = ImageIO.createImageInputStream(f);
        ImageReader r = ImageIO.getImageReaders(iis).next();
        r.setInput(iis);

        IIOImage dst = r.readAll(0, null);

        // look for iTXt node
        IIOMetadata m = dst.getMetadata();
        Node root = m.getAsTree(m.getNativeMetadataFormatName());
        Node n = root.getFirstChild();
        while (n != null && !"iTXt".equals(n.getNodeName())) {
            n = n.getNextSibling();
        }
        if (n == null) {
            throw new RuntimeException("No iTXt node!");
        }
        ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n);
        return t;
    } catch (Throwable e) {
        throw new RuntimeException("Reading test failed.", e);
    }
}
 
Example 5
public static void main(String[] args) throws Exception {
    String format = "javax_imageio_1.0";
    BufferedImage img =
        new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
    ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();
    IIOMetadata meta =
        iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null);
    DOMImplementationRegistry registry;
    registry = DOMImplementationRegistry.newInstance();
    DOMImplementation impl = registry.getDOMImplementation("XML 3.0");
    Document doc = impl.createDocument(null, format, null);
    Element root, text, entry;
    root = doc.getDocumentElement();
    root.appendChild(text = doc.createElement("Text"));
    text.appendChild(entry = doc.createElement("TextEntry"));
    // keyword isn't #REQUIRED by the standard metadata format.
    // However, it is required by the PNG format, so we include it here.
    entry.setAttribute("keyword", "Comment");
    entry.setAttribute("value", "Some demo comment");
    meta.mergeTree(format, root);
}
 
Example 6
Source Project: openjdk-jdk8u   Source File: GIFImageWriter.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void write(IIOMetadata sm,
                  IIOImage iioimage,
                  ImageWriteParam p) throws IOException {
    if (stream == null) {
        throw new IllegalStateException("output == null!");
    }
    if (iioimage == null) {
        throw new IllegalArgumentException("iioimage == null!");
    }
    if (iioimage.hasRaster()) {
        throw new UnsupportedOperationException("canWriteRasters() == false!");
    }

    resetLocal();

    GIFWritableStreamMetadata streamMetadata;
    if (sm == null) {
        streamMetadata =
            (GIFWritableStreamMetadata)getDefaultStreamMetadata(p);
    } else {
        streamMetadata =
            (GIFWritableStreamMetadata)convertStreamMetadata(sm, p);
    }

    write(true, true, streamMetadata, iioimage, p);
}
 
Example 7
Source Project: JDKSourceCode1.8   Source File: GIFImageWriter.java    License: MIT License 6 votes vote down vote up
public void prepareWriteSequence(IIOMetadata streamMetadata)
  throws IOException {

    if (stream == null) {
        throw new IllegalStateException("Output is not set.");
    }

    resetLocal();

    // Save the possibly converted stream metadata as an instance variable.
    if (streamMetadata == null) {
        this.theStreamMetadata =
            (GIFWritableStreamMetadata)getDefaultStreamMetadata(null);
    } else {
        this.theStreamMetadata = new GIFWritableStreamMetadata();
        convertMetadata(STREAM_METADATA_NAME, streamMetadata,
                        theStreamMetadata);
    }

    this.isWritingSequence = true;
}
 
Example 8
Source Project: Bytecoder   Source File: GIFImageWriter.java    License: Apache License 2.0 6 votes vote down vote up
public void write(IIOMetadata sm,
                  IIOImage iioimage,
                  ImageWriteParam p) throws IOException {
    if (stream == null) {
        throw new IllegalStateException("output == null!");
    }
    if (iioimage == null) {
        throw new IllegalArgumentException("iioimage == null!");
    }
    if (iioimage.hasRaster()) {
        throw new UnsupportedOperationException("canWriteRasters() == false!");
    }

    resetLocal();

    GIFWritableStreamMetadata streamMetadata;
    if (sm == null) {
        streamMetadata =
            (GIFWritableStreamMetadata)getDefaultStreamMetadata(p);
    } else {
        streamMetadata =
            (GIFWritableStreamMetadata)convertStreamMetadata(sm, p);
    }

    write(true, true, streamMetadata, iioimage, p);
}
 
Example 9
Source Project: Bytecoder   Source File: TIFFImageWriter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Converts a standard {@code javax_imageio_1.0} tree to a
 * {@code TIFFImageMetadata} object.
 *
 * @param inData The metadata object.
 * @return a {@code TIFFImageMetadata} or {@code null} if
 * the standard tree derived from the input object is {@code null}.
 * @throws IllegalArgumentException if {@code inData} is
 * {@code null}.
 * @throws IllegalArgumentException if {@code inData} does not support
 * the standard metadata format.
 * @throws IIOInvalidTreeException if {@code inData} generates an
 * invalid standard metadata tree.
 */
private TIFFImageMetadata convertStandardImageMetadata(IIOMetadata inData)
    throws IIOInvalidTreeException {

    if(inData == null) {
        throw new NullPointerException("inData == null!");
    } else if(!inData.isStandardMetadataFormatSupported()) {
        throw new IllegalArgumentException
            ("inData does not support standard metadata format!");
    }

    TIFFImageMetadata outData = null;

    String formatName = IIOMetadataFormatImpl.standardMetadataFormatName;
    Node tree = inData.getAsTree(formatName);
    if (tree != null) {
        List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
        tagSets.add(BaselineTIFFTagSet.getInstance());
        outData = new TIFFImageMetadata(tagSets);
        outData.setFromTree(formatName, tree);
    }

    return outData;
}
 
Example 10
public void prepareWriteSequence(IIOMetadata streamMetadata)
  throws IOException {

    if (stream == null) {
        throw new IllegalStateException("Output is not set.");
    }

    resetLocal();

    // Save the possibly converted stream metadata as an instance variable.
    if (streamMetadata == null) {
        this.theStreamMetadata =
            (GIFWritableStreamMetadata)getDefaultStreamMetadata(null);
    } else {
        this.theStreamMetadata = new GIFWritableStreamMetadata();
        convertMetadata(STREAM_METADATA_NAME, streamMetadata,
                        theStreamMetadata);
    }

    this.isWritingSequence = true;
}
 
Example 11
public IIOMetadata getImageMetadata(int imageIndex) throws IOException {

            if (input == null)
                throw new IllegalStateException();
            if (imageIndex >= 5 || imageIndex < 0)
                throw new IndexOutOfBoundsException();
            if (seekForwardOnly) {
                if (imageIndex < minIndex)
                    throw new IndexOutOfBoundsException();
                minIndex = imageIndex;
            }
            System.out.println("Current format class name " + DummyIIOMetadataFormatImpl.class.getName());
            return new DummyIIOMetadataImpl(true,
                                            DummyIIOMetadataFormatImpl.nativeMetadataFormatName,
                                            DummyIIOMetadataFormatImpl.class.getName(),
                                            null, null);
        }
 
Example 12
public static void main(String[] args) throws Exception {
    String format = "javax_imageio_1.0";
    BufferedImage img =
        new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
    ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();
    IIOMetadata meta =
        iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null);
    DOMImplementationRegistry registry;
    registry = DOMImplementationRegistry.newInstance();
    DOMImplementation impl = registry.getDOMImplementation("XML 3.0");
    Document doc = impl.createDocument(null, format, null);
    Element root, text, entry;
    root = doc.getDocumentElement();
    root.appendChild(text = doc.createElement("Text"));
    text.appendChild(entry = doc.createElement("TextEntry"));
    // keyword isn't #REQUIRED by the standard metadata format.
    // However, it is required by the PNG format, so we include it here.
    entry.setAttribute("keyword", "Comment");
    entry.setAttribute("value", "Some demo comment");
    meta.mergeTree(format, root);
}
 
Example 13
Source Project: sldeditor   Source File: LegendManager.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Save image.
 *
 * @param image the grid image
 * @param formatName the format name
 * @param destinationFile the output
 * @param dpi the dpi
 * @return true, if successful
 * @throws IOException Signals that an I/O exception has occurred.
 */
private boolean saveGridImage(
        BufferedImage image, String formatName, File destinationFile, int dpi)
        throws IOException {
    if (!Files.delete(destinationFile)) {
        ConsoleManager.getInstance()
                .information(
                        this,
                        String.format(
                                "Failed to delete '%s'", destinationFile.getAbsolutePath()));
    }

    boolean finish = false;

    for (Iterator<ImageWriter> iw = ImageIO.getImageWritersByFormatName(formatName);
            iw.hasNext() && !finish; ) {
        ImageWriter writer = iw.next();
        ImageWriteParam writeParam = writer.getDefaultWriteParam();
        ImageTypeSpecifier typeSpecifier =
                ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
        IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
        if (!(metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported())) {

            setDPI(metadata, dpi);

            final ImageOutputStream stream = ImageIO.createImageOutputStream(destinationFile);
            try {
                writer.setOutput(stream);
                writer.write(metadata, new IIOImage(image, null, metadata), writeParam);
            } finally {
                stream.close();
            }
            finish = true;
        }
    }

    return true;
}
 
Example 14
Source Project: openjdk-jdk9   Source File: ITXtTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void writeTo(File f, ITXtTest t) {
    BufferedImage src = createBufferedImage();
    try (ImageOutputStream imageOutputStream =
            ImageIO.createImageOutputStream(f)) {

        ImageTypeSpecifier imageTypeSpecifier =
            new ImageTypeSpecifier(src);
        ImageWriter imageWriter =
            ImageIO.getImageWritersByFormatName("PNG").next();

        imageWriter.setOutput(imageOutputStream);

        IIOMetadata m =
            imageWriter.getDefaultImageMetadata(imageTypeSpecifier, null);

        String format = m.getNativeMetadataFormatName();
        Node root = m.getAsTree(format);

        IIOMetadataNode iTXt = t.getNode();
        root.appendChild(iTXt);
        m.setFromTree(format, root);

        imageWriter.write(new IIOImage(src, null, m));
        System.out.println("Writing done.");
    } catch (Throwable e) {
        throw new RuntimeException("Writing test failed.", e);
    }
}
 
Example 15
Source Project: Bytecoder   Source File: JPEGImageWriter.java    License: Apache License 2.0 5 votes vote down vote up
public IIOMetadata getDefaultStreamMetadata(ImageWriteParam param) {
    setThreadLock();
    try {
        return new JPEGMetadata(param, this);
    } finally {
        clearThreadLock();
    }
}
 
Example 16
Source Project: JewelCrawler   Source File: ImageIOHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static File createImage(File imageFile, String imageFormat) {
	File tempFile = null;
	try {
		Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(imageFormat);
		ImageReader reader = readers.next();

		ImageInputStream iis = ImageIO.createImageInputStream(imageFile);
		reader.setInput(iis);
		// Read the stream metadata
		IIOMetadata streamMetadata = reader.getStreamMetadata();

		// Set up the writeParam
		TIFFImageWriteParam tiffWriteParam = new TIFFImageWriteParam(Locale.US);
		tiffWriteParam.setCompressionMode(ImageWriteParam.MODE_DISABLED);

		// Get tif writer and set output to file
		Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("tiff");
		ImageWriter writer = writers.next();

		BufferedImage bi = reader.read(0);
		IIOImage image = new IIOImage(bi, null, reader.getImageMetadata(0));
		tempFile = tempImageFile(imageFile);
		ImageOutputStream ios = ImageIO.createImageOutputStream(tempFile);
		writer.setOutput(ios);
		writer.write(streamMetadata, image, tiffWriteParam);
		ios.close();

		writer.dispose();
		reader.dispose();
	} catch (Exception exc) {
		exc.printStackTrace();
	}
	return tempFile;
}
 
Example 17
public IIOMetadata convertImageMetadata(IIOMetadata inData,
                                        ImageTypeSpecifier imageType,
                                        ImageWriteParam param) {
    // TODO - deal with imageType
    if (inData instanceof PNGMetadata) {
        return (PNGMetadata)((PNGMetadata)inData).clone();
    } else {
        return new PNGMetadata(inData);
    }
}
 
Example 18
Source Project: jdk1.8-source-analysis   Source File: GIFImageWriter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a default stream metadata object and merges in the
 * supplied metadata.
 */
public IIOMetadata convertStreamMetadata(IIOMetadata inData,
                                         ImageWriteParam param) {
    if (inData == null) {
        throw new IllegalArgumentException("inData == null!");
    }

    IIOMetadata sm = getDefaultStreamMetadata(param);

    convertMetadata(STREAM_METADATA_NAME, inData, sm);

    return sm;
}
 
Example 19
Source Project: jdk1.8-source-analysis   Source File: GIFImageWriter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a default image metadata object and merges in the
 * supplied metadata.
 */
public IIOMetadata convertImageMetadata(IIOMetadata inData,
                                        ImageTypeSpecifier imageType,
                                        ImageWriteParam param) {
    if (inData == null) {
        throw new IllegalArgumentException("inData == null!");
    }
    if (imageType == null) {
        throw new IllegalArgumentException("imageType == null!");
    }

    GIFWritableImageMetadata im =
        (GIFWritableImageMetadata)getDefaultImageMetadata(imageType,
                                                          param);

    // Save interlace flag state.

    boolean isProgressive = im.interlaceFlag;

    convertMetadata(IMAGE_METADATA_NAME, inData, im);

    // Undo change to interlace flag if not MODE_COPY_FROM_METADATA.

    if (param != null && param.canWriteProgressive() &&
        param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) {
        im.interlaceFlag = isProgressive;
    }

    return im;
}
 
Example 20
Source Project: hottub   Source File: JPEGImageWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void write(IIOMetadata streamMetadata,
                  IIOImage image,
                  ImageWriteParam param) throws IOException {
    setThreadLock();
    try {
        cbLock.check();

        writeOnThread(streamMetadata, image, param);
    } finally {
        clearThreadLock();
    }
}
 
Example 21
/**
 * Merges <code>inData</code> into <code>outData</code>. The supplied
 * metadata format name is attempted first and failing that the standard
 * metadata format name is attempted.
 */
private void convertMetadata(String metadataFormatName,
                             IIOMetadata inData,
                             IIOMetadata outData) {
    String formatName = null;

    String nativeFormatName = inData.getNativeMetadataFormatName();
    if (nativeFormatName != null &&
        nativeFormatName.equals(metadataFormatName)) {
        formatName = metadataFormatName;
    } else {
        String[] extraFormatNames = inData.getExtraMetadataFormatNames();

        if (extraFormatNames != null) {
            for (int i = 0; i < extraFormatNames.length; i++) {
                if (extraFormatNames[i].equals(metadataFormatName)) {
                    formatName = metadataFormatName;
                    break;
                }
            }
        }
    }

    if (formatName == null &&
        inData.isStandardMetadataFormatSupported()) {
        formatName = STANDARD_METADATA_NAME;
    }

    if (formatName != null) {
        try {
            Node root = inData.getAsTree(formatName);
            outData.mergeTree(formatName, root);
        } catch(IIOInvalidTreeException e) {
            // ignore
        }
    }
}
 
Example 22
Source Project: MyBox   Source File: ImageFileWriters.java    License: Apache License 2.0 5 votes vote down vote up
public static IIOMetadata getWriterMetaData(String targetFormat,
        ImageAttributes attributes, BufferedImage image, ImageWriter writer,
        ImageWriteParam param) {
    try {
        IIOMetadata metaData;
        switch (targetFormat) {
            case "png":
                metaData = ImagePngFile.getWriterMeta(attributes, image, writer, param);
                break;
            case "jpg":
            case "jpeg":
                metaData = ImageJpgFile.getWriterMeta(attributes, image, writer, param);
                break;
            case "tif":
            case "tiff":
                metaData = ImageTiffFile.getWriterMeta(attributes, image, writer, param);
                break;
            case "bmp":
                metaData = ImageBmpFile.getWriterMeta(attributes, image, writer, param);
                break;
            default:
                metaData = getWriterMetaData(attributes, image, writer, param);
        }
        return metaData;
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example 23
Source Project: Bytecoder   Source File: JPEGImageWriter.java    License: Apache License 2.0 5 votes vote down vote up
public Dimension[] getPreferredThumbnailSizes(ImageTypeSpecifier imageType,
                                              ImageWriteParam param,
                                              IIOMetadata streamMetadata,
                                              IIOMetadata imageMetadata) {
    if (jfifOK(imageType, param, streamMetadata, imageMetadata)) {
        return preferredThumbSizes.clone();
    }
    return null;
}
 
Example 24
/**
 * Creates a default image metadata object and merges in the
 * supplied metadata.
 */
public IIOMetadata convertImageMetadata(IIOMetadata inData,
                                        ImageTypeSpecifier imageType,
                                        ImageWriteParam param) {
    if (inData == null) {
        throw new IllegalArgumentException("inData == null!");
    }
    if (imageType == null) {
        throw new IllegalArgumentException("imageType == null!");
    }

    GIFWritableImageMetadata im =
        (GIFWritableImageMetadata)getDefaultImageMetadata(imageType,
                                                          param);

    // Save interlace flag state.

    boolean isProgressive = im.interlaceFlag;

    convertMetadata(IMAGE_METADATA_NAME, inData, im);

    // Undo change to interlace flag if not MODE_COPY_FROM_METADATA.

    if (param != null && param.canWriteProgressive() &&
        param.getProgressiveMode() != param.MODE_COPY_FROM_METADATA) {
        im.interlaceFlag = isProgressive;
    }

    return im;
}
 
Example 25
Source Project: jdk8u60   Source File: GIFImageWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a default stream metadata object and merges in the
 * supplied metadata.
 */
public IIOMetadata convertStreamMetadata(IIOMetadata inData,
                                         ImageWriteParam param) {
    if (inData == null) {
        throw new IllegalArgumentException("inData == null!");
    }

    IIOMetadata sm = getDefaultStreamMetadata(param);

    convertMetadata(STREAM_METADATA_NAME, inData, sm);

    return sm;
}
 
Example 26
public static void main(String[] args) throws IIOInvalidTreeException {

        // getting the writer for the png format
        Iterator iter = ImageIO.getImageWritersByFormatName("png");
        ImageWriter writer = (ImageWriter) iter.next();

        // creating a color model
        ColorModel colorModel = ColorModel.getRGBdefault();

        // creating a sample model
        SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480);

        // creating a default metadata object
        IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null);
        String formatName = metaData.getNativeMetadataFormatName();

        // first call
        Node metaDataNode = metaData.getAsTree(formatName);
        try {
            metaData.setFromTree(formatName, metaDataNode);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        // second call (bitdepht is already set to an invalid value)
        metaDataNode = metaData.getAsTree(formatName);

        metaData.setFromTree(formatName, metaDataNode);

    }
 
Example 27
Source Project: JDKSourceCode1.8   Source File: JPEGImageWriter.java    License: MIT License 5 votes vote down vote up
public void prepareWriteSequence(IIOMetadata streamMetadata)
    throws IOException {
    setThreadLock();
    try {
        cbLock.check();

        prepareWriteSequenceOnThread(streamMetadata);
    } finally {
        clearThreadLock();
    }
}
 
Example 28
Source Project: MyBox   Source File: ImageTiffFile.java    License: Apache License 2.0 5 votes vote down vote up
public static IIOMetadata getTiffIIOMetadata(File file) {
    try {
        ImageReader reader = ImageIO.getImageReadersByFormatName("tif").next();
        try (ImageInputStream iis = ImageIO.createImageInputStream(file)) {
            reader.setInput(iis, false);
            IIOMetadata metadata = reader.getImageMetadata(0);
            reader.dispose();
            return metadata;
        }
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example 29
Source Project: hottub   Source File: BMPImageWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
                                           ImageWriteParam param) {
    BMPMetadata meta = new BMPMetadata();
    meta.bmpVersion = VERSION_3;
    meta.compression = getPreferredCompressionType(imageType);
    if (param != null
        && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
        meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
    }
    meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
    return meta;
}
 
Example 30
Source Project: hottub   Source File: JPEGImageWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public IIOMetadata
    getDefaultImageMetadata(ImageTypeSpecifier imageType,
                            ImageWriteParam param) {
    setThreadLock();
    try {
        return new JPEGMetadata(imageType, param, this);
    } finally {
        clearThreadLock();
    }
}