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