Search in sources :

Example 11 with ImageWriterSpi

use of javax.imageio.spi.ImageWriterSpi in project jdk8u_jdk by JetBrains.

the class NullInputOutput method main.

public static void main(String[] args) throws Exception {
    IIORegistry registry = IIORegistry.getDefaultInstance();
    // test ImageReader.read() for all available ImageReaders
    Iterator readerspis = registry.getServiceProviders(ImageReaderSpi.class, false);
    while (readerspis.hasNext()) {
        ImageReaderSpi readerspi = (ImageReaderSpi) readerspis.next();
        ImageReader reader = readerspi.createReaderInstance();
        try {
            reader.read(0);
        } catch (IllegalStateException ise) {
        // caught exception, everything's okay
        }
    }
    // test ImageWriter.write() for all available ImageWriters
    BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
    Iterator writerspis = registry.getServiceProviders(ImageWriterSpi.class, false);
    while (writerspis.hasNext()) {
        ImageWriterSpi writerspi = (ImageWriterSpi) writerspis.next();
        ImageWriter writer = writerspi.createWriterInstance();
        try {
            writer.write(bi);
        } catch (IllegalStateException ise) {
        // caught exception, everything's okay
        }
    }
}
Also used : IIORegistry(javax.imageio.spi.IIORegistry) ImageReaderSpi(javax.imageio.spi.ImageReaderSpi) Iterator(java.util.Iterator) ImageWriter(javax.imageio.ImageWriter) ImageReader(javax.imageio.ImageReader) ImageWriterSpi(javax.imageio.spi.ImageWriterSpi) BufferedImage(java.awt.image.BufferedImage)

Example 12 with ImageWriterSpi

use of javax.imageio.spi.ImageWriterSpi 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 13 with ImageWriterSpi

use of javax.imageio.spi.ImageWriterSpi in project jdk8u_jdk by JetBrains.

the class PNGSpiStreamMetadata method main.

public static void main(String[] args) {
    ImageReaderSpi rspi = new PNGImageReaderSpi();
    if (rspi.getNativeStreamMetadataFormatName() != null) {
        fatal();
    }
    if (rspi.isStandardStreamMetadataFormatSupported() != false) {
        fatal();
    }
    if (rspi.getExtraStreamMetadataFormatNames() != null) {
        fatal();
    }
    ImageWriterSpi wspi = new PNGImageWriterSpi();
    if (wspi.getNativeStreamMetadataFormatName() != null) {
        fatal();
    }
    if (wspi.isStandardStreamMetadataFormatSupported() != false) {
        fatal();
    }
    if (wspi.getExtraStreamMetadataFormatNames() != null) {
        fatal();
    }
}
Also used : ImageReaderSpi(javax.imageio.spi.ImageReaderSpi) PNGImageReaderSpi(com.sun.imageio.plugins.png.PNGImageReaderSpi) PNGImageWriterSpi(com.sun.imageio.plugins.png.PNGImageWriterSpi) PNGImageReaderSpi(com.sun.imageio.plugins.png.PNGImageReaderSpi) PNGImageWriterSpi(com.sun.imageio.plugins.png.PNGImageWriterSpi) ImageWriterSpi(javax.imageio.spi.ImageWriterSpi)

Example 14 with ImageWriterSpi

use of javax.imageio.spi.ImageWriterSpi in project jdk8u_jdk by JetBrains.

the class SpiTest method testImageWriterSpiConstructor.

public void testImageWriterSpiConstructor() {
    resetConstructorArguments();
    checkImageWriterSpiConstructor(true);
    vendorName = "My Vendor";
    checkImageWriterSpiConstructor(true);
    version = "My Version";
    checkImageWriterSpiConstructor(true);
    names = new String[0];
    checkImageWriterSpiConstructor(true);
    names = new String[1];
    names[0] = "My Format Name";
    checkImageWriterSpiConstructor(true);
    writerClassName = "com.mycompany.Writer";
    checkImageWriterSpiConstructor(true);
    outputTypes = new Class[0];
    checkImageWriterSpiConstructor(true);
    outputTypes = new Class[1];
    outputTypes[0] = Object.class;
    // Now it should work
    checkImageWriterSpiConstructor(false);
    // Test normalization of zero-length arrays
    suffixes = new String[0];
    MIMETypes = new String[0];
    readerSpiNames = new String[0];
    extraStreamMetadataFormatNames = new String[0];
    extraStreamMetadataFormatClassNames = new String[0];
    extraImageMetadataFormatNames = new String[0];
    extraImageMetadataFormatClassNames = new String[0];
    ImageWriterSpi spi = constructImageWriterSpi();
    if (spi.getFileSuffixes() != null) {
        error("Failed to normalize suffixes!");
    }
    if (spi.getMIMETypes() != null) {
        error("Failed to normalize MIMETypes!");
    }
    if (spi.getImageReaderSpiNames() != null) {
        error("Failed to normalize readerSpiNames!");
    }
    if (spi.getExtraStreamMetadataFormatNames() != null) {
        error("Failed to normalize extraStreamMetadataFormatNames!");
    }
    if (spi.getExtraImageMetadataFormatNames() != null) {
        error("Failed to normalize extraImageMetadataFormatNames!");
    }
}
Also used : ImageWriterSpi(javax.imageio.spi.ImageWriterSpi)

Example 15 with ImageWriterSpi

use of javax.imageio.spi.ImageWriterSpi in project jdk8u_jdk by JetBrains.

the class CanWriteSequence method main.

public static void main(final String[] args) throws Exception {
    final IIORegistry registry = IIORegistry.getDefaultInstance();
    final Iterator<ImageWriterSpi> iter = registry.getServiceProviders(ImageWriterSpi.class, provider -> true, true);
    // Validates all supported ImageWriters
    while (iter.hasNext()) {
        final ImageWriter writer = iter.next().createWriterInstance();
        System.out.println("ImageWriter = " + writer);
        test(writer);
    }
    System.out.println("Test passed");
}
Also used : IIORegistry(javax.imageio.spi.IIORegistry) ImageWriter(javax.imageio.ImageWriter) ImageWriterSpi(javax.imageio.spi.ImageWriterSpi)

Aggregations

ImageWriterSpi (javax.imageio.spi.ImageWriterSpi)15 Iterator (java.util.Iterator)5 ImageWriter (javax.imageio.ImageWriter)5 ImageReaderSpi (javax.imageio.spi.ImageReaderSpi)5 IIORegistry (javax.imageio.spi.IIORegistry)4 IOException (java.io.IOException)3 BufferedImage (java.awt.image.BufferedImage)2 File (java.io.File)2 PNGImageReaderSpi (com.sun.imageio.plugins.png.PNGImageReaderSpi)1 PNGImageWriterSpi (com.sun.imageio.plugins.png.PNGImageWriterSpi)1 BandedSampleModel (java.awt.image.BandedSampleModel)1 ComponentSampleModel (java.awt.image.ComponentSampleModel)1 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)1 SampleModel (java.awt.image.SampleModel)1 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1