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
}
}
}
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;
}
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();
}
}
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!");
}
}
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");
}
Aggregations