use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.
the class BMPWriteParamTest method getWriteResult.
private static BufferedImage getWriteResult(BufferedImage img, String format) throws IOException {
ImageWriter iw = null;
Iterator writers = ImageIO.getImageWritersByFormatName(format);
while (writers.hasNext()) {
iw = (ImageWriter) writers.next();
System.out.println(format + " -> " + iw.toString());
}
if (iw == null) {
throw new RuntimeException("No available Image writer for " + format);
}
ImageWriteParam param = iw.getDefaultWriteParam();
param.setSourceRegion(new Rectangle(10, 10, 31, 31));
param.setSourceSubsampling(3, 3, 0, 0);
IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);
IIOImage iio_img = new IIOImage(img, null, meta);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
iw.setOutput(ios);
iw.write(meta, iio_img, param);
ios.flush();
byte[] ba_image = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(ba_image);
ImageReader ir = null;
Iterator readers = ImageIO.getImageReadersByFormatName(format);
while (readers.hasNext()) {
ir = (ImageReader) readers.next();
System.out.println(format + " -> " + ir.toString());
}
if (ir == null) {
throw new RuntimeException("No available Image reader for " + format);
}
ir.setInput(ImageIO.createImageInputStream(bais));
BufferedImage res = ir.read(0);
return res;
}
use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.
the class LogicalScreenDimensionTest method main.
public static void main(String[] args) throws IOException {
String format = "GIF";
ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next();
if (writer == null) {
throw new RuntimeException("No available writers for " + format);
}
BufferedImage img = createTestImage(100, 100, BufferedImage.TYPE_BYTE_GRAY);
ImageWriteParam p = writer.getDefaultWriteParam();
ImageTypeSpecifier type = ImageTypeSpecifier.createFromRenderedImage(img);
IIOMetadata inImageMetadata = writer.getDefaultImageMetadata(type, p);
IIOMetadata inStreamMetadata = writer.getDefaultStreamMetadata(p);
// write and read image
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
writer.setOutput(ios);
writer.write(inStreamMetadata, new IIOImage(img, null, inImageMetadata), p);
ios.flush();
ios.close();
// read result
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ImageInputStream iis = ImageIO.createImageInputStream(bais);
ImageReader reader = ImageIO.getImageReader(writer);
reader.setInput(iis);
IIOMetadata outStreamMetadata = reader.getStreamMetadata();
GIFStreamMetadata gifStreamMetadata = (GIFStreamMetadata) outStreamMetadata;
if (gifStreamMetadata.logicalScreenWidth != img.getWidth() || gifStreamMetadata.logicalScreenHeight != img.getHeight()) {
throw new RuntimeException("Test failed due to wrong logical screen dimension.");
}
}
use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.
the class RGBImageTest method doTest.
protected void doTest() throws IOException {
BufferedImage biSrc = getSrc();
ImageWriter writer = ImageIO.getImageWritersByFormatName("GIF").next();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
writer.setOutput(ios);
ImageWriteParam writeParam = writer.getDefaultWriteParam();
IIOMetadata imageMetadata = writer.getDefaultImageMetadata(new ImageTypeSpecifier(biSrc), writeParam);
IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(writeParam);
IIOImage iioImg = new IIOImage(biSrc, null, imageMetadata);
writer.write(streamMetadata, iioImg, writeParam);
ios.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ImageInputStream iis = ImageIO.createImageInputStream(bais);
ImageReader reader = ImageIO.getImageReader(writer);
reader.setInput(iis);
BufferedImage dst = reader.read(0);
// do test
int x = dx / 2;
int y = height / 2;
for (int i = 0; i < usedColors.length; i++) {
int dstRgb = dst.getRGB(x, y);
System.out.println("dstColor: " + Integer.toHexString(dstRgb));
int srcRgb = usedColors[i].getRGB();
System.out.println("srcColor: " + Integer.toHexString(srcRgb));
if (dstRgb != srcRgb) {
throw new RuntimeException("wrong color " + i + ": " + Integer.toHexString(dstRgb));
}
x += dx;
}
}
use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.
the class WriteMetadataTest method main.
public static void main(String[] args) {
ImageWriter w = ImageIO.getImageWritersByFormatName(format).next();
if (w == null) {
throw new RuntimeException("No available writers for format " + format);
}
ImageWriteParam p = w.getDefaultWriteParam();
ImageTypeSpecifier t = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
IIOMetadata m = w.getDefaultImageMetadata(t, p);
System.out.println("Default image metadata is " + m);
testWritableMetadata(m);
IIOMetadata sm = w.getDefaultStreamMetadata(p);
System.out.println("Default stream metadata is " + sm);
testWritableMetadata(sm);
}
use of javax.imageio.ImageTypeSpecifier in project jdk8u_jdk by JetBrains.
the class CanEncodeIndexed method main.
public static void main(String[] args) {
BufferedImage img = new BufferedImage(32, 32, BufferedImage.TYPE_BYTE_INDEXED);
ImageTypeSpecifier spec = ImageTypeSpecifier.createFromRenderedImage(img);
Iterator writers = ImageIO.getImageWriters(spec, "jpeg");
if (!writers.hasNext()) {
throw new RuntimeException("Test failed: " + "no JPEG writer found for " + "image with IndexColorModel");
}
}
Aggregations