Search in sources :

Example 51 with ImageTypeSpecifier

use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.

the class UshortGrayTest method main.

public static void main(String[] args) {
    Iterator iter;
    BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_USHORT_GRAY);
    // Part 1: ensure that JPEGImageWriter throws an exception if it
    // encounters an image with 16-bit samples
    ImageWriter writer = null;
    iter = ImageIO.getImageWritersByFormatName("jpeg");
    if (iter.hasNext()) {
        writer = (ImageWriter) iter.next();
    } else {
        throw new RuntimeException("No JPEG reader found");
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageOutputStream ios = null;
    boolean exceptionThrown = false;
    try {
        ios = ImageIO.createImageOutputStream(baos);
    } catch (IOException ioe) {
        throw new RuntimeException("Could not create ImageOutputStream");
    }
    try {
        writer.setOutput(ios);
        writer.write(bi);
    } catch (IOException ioe) {
        exceptionThrown = true;
    }
    if (!exceptionThrown) {
        throw new RuntimeException("JPEG writer should not be able to " + "write USHORT_GRAY images");
    }
    // Part 2: ensure that JPEGImageWriterSpi.canEncodeImage() returns
    // false for images with 16-bit samples
    ImageTypeSpecifier its = ImageTypeSpecifier.createFromRenderedImage(bi);
    iter = ImageIO.getImageWriters(its, "jpeg");
    if (iter.hasNext()) {
        throw new RuntimeException("JPEG writer should not be available" + " for USHORT_GRAY images");
    }
}
Also used : Iterator(java.util.Iterator) ImageWriter(javax.imageio.ImageWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) ImageOutputStream(javax.imageio.stream.ImageOutputStream) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Example 52 with ImageTypeSpecifier

use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.

the class MergeStdCommentTest method main.

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);
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) Element(org.w3c.dom.Element) ImageWriter(javax.imageio.ImageWriter) DOMImplementationRegistry(org.w3c.dom.bootstrap.DOMImplementationRegistry) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document) BufferedImage(java.awt.image.BufferedImage) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Example 53 with ImageTypeSpecifier

use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.

the class DestTypeTest method getWriteParam.

public ImageWriteParam getWriteParam() {
    ImageWriteParam p = w.getDefaultWriteParam();
    p.setSourceBands(new int[] { 0, 1, 2 });
    ImageTypeSpecifier type = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
    p.setDestinationType(type);
    return p;
}
Also used : ImageWriteParam(javax.imageio.ImageWriteParam) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Example 54 with ImageTypeSpecifier

use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.

the class ImageTypeSpecifierTest method test4429934.

private static void test4429934() {
    try {
        ImageTypeSpecifier itspecifier = new ImageTypeSpecifier(null, null);
        fail("Failed to get IAE!");
    } catch (IllegalArgumentException e) {
    }
    try {
        ImageTypeSpecifier itspecifier = new ImageTypeSpecifier(null);
        fail("Failed to get IAE!");
    } catch (IllegalArgumentException e) {
    }
}
Also used : ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Example 55 with ImageTypeSpecifier

use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.

the class ImageTypeSpecifierTest method test4430993.

private static void test4430993() {
    ImageTypeSpecifier itspecifier;
    int bits = 32;
    int rmask = 0x00ff0000;
    int gmask = 0x0000ff00;
    int bmask = 0x000000ff;
    ColorModel dcm = new java.awt.image.DirectColorModel(bits, rmask, gmask, bmask);
    int[] bandOffsets = new int[2];
    bandOffsets[1] = 1;
    SampleModel sm = new java.awt.image.ComponentSampleModel(DataBuffer.TYPE_SHORT, 1, 1, 2, 2, bandOffsets);
    try {
        itspecifier = new ImageTypeSpecifier(dcm, sm);
        fail("Failed to get IAE!");
    } catch (IllegalArgumentException e) {
    }
}
Also used : SampleModel(java.awt.image.SampleModel) ColorModel(java.awt.image.ColorModel) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

Aggregations

ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)88 BufferedImage (java.awt.image.BufferedImage)36 IIOMetadata (javax.imageio.metadata.IIOMetadata)32 ImageWriter (javax.imageio.ImageWriter)29 IIOImage (javax.imageio.IIOImage)23 IOException (java.io.IOException)22 ImageOutputStream (javax.imageio.stream.ImageOutputStream)22 ColorModel (java.awt.image.ColorModel)20 ImageReader (javax.imageio.ImageReader)20 SampleModel (java.awt.image.SampleModel)18 ImageWriteParam (javax.imageio.ImageWriteParam)18 ImageReadParam (javax.imageio.ImageReadParam)16 Rectangle (java.awt.Rectangle)14 File (java.io.File)13 Iterator (java.util.Iterator)12 ColorSpace (java.awt.color.ColorSpace)11 IndexColorModel (java.awt.image.IndexColorModel)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 Point (java.awt.Point)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9