Search in sources :

Example 76 with IIOImage

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

the class ITXtTest method readFrom.

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);
    }
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) ImageInputStream(javax.imageio.stream.ImageInputStream) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Node(org.w3c.dom.Node) ImageReader(javax.imageio.ImageReader) IIOImage(javax.imageio.IIOImage)

Example 77 with IIOImage

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

the class DestTypeTest method writeTest.

public byte[] writeTest(BufferedImage bi, ImageWriteParam p, IIOMetadata m) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // write test image as jpeg
    ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
    w.setOutput(ios);
    w.write(null, new IIOImage(bi, null, m), p);
    ios.close();
    return baos.toByteArray();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImageOutputStream(javax.imageio.stream.ImageOutputStream) IIOImage(javax.imageio.IIOImage)

Example 78 with IIOImage

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

the class BMPPluginTest 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);
    System.out.println("Image type " + img.getType());
    ImageWriterSpi spi = iw.getOriginatingProvider();
    boolean bCanEncode = spi.canEncodeImage(img);
    System.out.println("Can encode image? " + (bCanEncode ? "YES" : "NO"));
    if (!bCanEncode) {
        return true;
    }
    IIOImage iio_img = new IIOImage(img, null, md);
    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 : ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) FileInputStream(java.io.FileInputStream) BufferedImage(java.awt.image.BufferedImage) IIOImage(javax.imageio.IIOImage) IIOMetadata(javax.imageio.metadata.IIOMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) ImageWriterSpi(javax.imageio.spi.ImageWriterSpi) File(java.io.File)

Example 79 with IIOImage

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

the class EncodeSubImageTest method write.

private void write(File f, boolean subsample) throws IOException {
    ImageOutputStream ios = ImageIO.createImageOutputStream(f);
    writer.setOutput(ios);
    ImageWriteParam p = writer.getDefaultWriteParam();
    if (subsample) {
        p.setSourceSubsampling(subSampleX, subSampleY, 0, 0);
    }
    writer.write(null, new IIOImage(img, null, null), p);
    ios.close();
    writer.reset();
}
Also used : ImageWriteParam(javax.imageio.ImageWriteParam) ImageOutputStream(javax.imageio.stream.ImageOutputStream) IIOImage(javax.imageio.IIOImage)

Example 80 with IIOImage

use of javax.imageio.IIOImage 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)

Aggregations

IIOImage (javax.imageio.IIOImage)123 ImageWriter (javax.imageio.ImageWriter)92 ImageWriteParam (javax.imageio.ImageWriteParam)79 ImageOutputStream (javax.imageio.stream.ImageOutputStream)79 BufferedImage (java.awt.image.BufferedImage)66 File (java.io.File)45 IOException (java.io.IOException)41 ByteArrayOutputStream (java.io.ByteArrayOutputStream)37 IIOMetadata (javax.imageio.metadata.IIOMetadata)32 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)25 ByteArrayInputStream (java.io.ByteArrayInputStream)22 FileImageOutputStream (javax.imageio.stream.FileImageOutputStream)17 ImageReader (javax.imageio.ImageReader)16 MemoryCacheImageOutputStream (javax.imageio.stream.MemoryCacheImageOutputStream)16 Graphics2D (java.awt.Graphics2D)14 JPEGImageWriteParam (javax.imageio.plugins.jpeg.JPEGImageWriteParam)14 Test (org.junit.Test)14 FileOutputStream (java.io.FileOutputStream)13 Iterator (java.util.Iterator)11 RenderedImage (java.awt.image.RenderedImage)10