use of javax.imageio.metadata.IIOMetadata 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);
}
}
use of javax.imageio.metadata.IIOMetadata 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);
}
use of javax.imageio.metadata.IIOMetadata 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.metadata.IIOMetadata in project jdk8u_jdk by JetBrains.
the class UshortOutOfMemoryTest method testGetAsTree.
public void testGetAsTree() {
ImageWriteParam p = w.getDefaultWriteParam();
IIOMetadata m = w.getDefaultImageMetadata(ImageTypeSpecifier.createFromBufferedImageType(type), p);
String format = m.getNativeMetadataFormatName();
System.out.println("native format: " + format);
int count = 0;
try {
while (count < 100) {
System.out.println(" test " + count++);
m.getAsTree(format);
}
} catch (OutOfMemoryError e) {
System.gc();
throw new RuntimeException("Test failed. Number of performed operations: " + count, e);
}
}
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;
}
Aggregations