Search in sources :

Example 36 with IIOMetadata

use of javax.imageio.metadata.IIOMetadata in project jdk8u_jdk by JetBrains.

the class WBMPPluginTest method test.

public boolean test() throws IIOException, IOException {
    ir.reset();
    iw.reset();
    String[] suffixes = iw.getOriginatingProvider().getFileSuffixes();
    IIOMetadata md = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);
    IIOImage iio_img = new IIOImage(img, null, md);
    System.out.println("Image type " + img.getType());
    String fname = "test" + img.getType() + "." + suffixes[0];
    iw.setOutput(ImageIO.createImageOutputStream(new FileOutputStream(new File(fname))));
    System.out.print("write image ... ");
    iw.write(iio_img);
    System.out.println("OK");
    System.out.print("read image ... ");
    byte[] ba_image = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(ba_image);
    ir.setInput(ImageIO.createImageInputStream(new FileInputStream(new File(fname))));
    BufferedImage res = ir.read(0);
    System.out.println("OK");
    System.out.print("compare images ... ");
    boolean r = compare(img, res);
    System.out.println(r ? "OK" : "FAILED");
    return r;
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) FileInputStream(java.io.FileInputStream) BufferedImage(java.awt.image.BufferedImage) IIOImage(javax.imageio.IIOImage)

Example 37 with IIOMetadata

use of javax.imageio.metadata.IIOMetadata in project jdk8u_jdk by JetBrains.

the class PngOutputTypeTest method checkImageType.

private boolean checkImageType() throws IOException {
    IIOMetadata md = null;
    try {
        md = reader.getImageMetadata(0);
    } catch (IOException e) {
        return false;
    }
    String format = md.getNativeMetadataFormatName();
    Node root = md.getAsTree(format);
    Node ihdr = getNode(root, "IHDR");
    if (ihdr == null) {
        throw new RuntimeException("No ihdr node: invalid png image!");
    }
    String colorType = getAttributeValue(ihdr, "colorType");
    System.out.println("ColorType: " + colorType);
    if ("RGB".equals(colorType) || "RGBAlpha".equals(colorType)) {
        // we shuld chek bitDepth
        System.out.println("Good color type!");
        String bitDepthStr = getAttributeValue(ihdr, "bitDepth");
        System.out.println("bitDepth: " + bitDepthStr);
        int bitDepth = -1;
        try {
            bitDepth = Integer.parseInt(bitDepthStr);
        } catch (NumberFormatException e) {
            throw new RuntimeException("Invalid bitDepth!");
        }
        if (bitDepth == 8) {
            /*
                 * This image is RGB or RGBA color type and
                 * 8 bit tepth. so it can be used for test
                 */
            return true;
        }
    }
    return false;
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) Node(org.w3c.dom.Node) IOException(java.io.IOException)

Aggregations

IIOMetadata (javax.imageio.metadata.IIOMetadata)37 BufferedImage (java.awt.image.BufferedImage)20 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)20 ImageWriter (javax.imageio.ImageWriter)18 IIOImage (javax.imageio.IIOImage)17 ImageOutputStream (javax.imageio.stream.ImageOutputStream)15 ImageWriteParam (javax.imageio.ImageWriteParam)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ImageReader (javax.imageio.ImageReader)9 File (java.io.File)8 IOException (java.io.IOException)7 Node (org.w3c.dom.Node)7 Rectangle (java.awt.Rectangle)5 ImageInputStream (javax.imageio.stream.ImageInputStream)5 FileOutputStream (java.io.FileOutputStream)4 IIOMetadataNode (javax.imageio.metadata.IIOMetadataNode)4 Graphics (java.awt.Graphics)3 Point (java.awt.Point)3 ColorModel (java.awt.image.ColorModel)3