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;
}
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;
}
Aggregations