use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class CompressionModeTest method doTest.
private static void doTest(int mode) {
String fileFormat = "bmp";
try {
ImageWriter iw = (ImageWriter) ImageIO.getImageWritersBySuffix(fileFormat).next();
if (iw == null) {
throw new RuntimeException("No available image writer for " + fileFormat + " Test failed.");
}
File file = new File("image." + fileFormat);
ImageOutputStream ios = ImageIO.createImageOutputStream(file);
iw.setOutput(ios);
BufferedImage bimg = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
Graphics g = bimg.getGraphics();
g.setColor(Color.green);
g.fillRect(0, 0, 100, 100);
ImageWriteParam param = iw.getDefaultWriteParam();
param.setCompressionMode(mode);
IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(bimg), param);
IIOImage iioImg = new IIOImage(bimg, null, meta);
iw.write(null, iioImg, param);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Test failed.");
}
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class AnimationTest method main.
public static void main(String[] args) {
try {
AnimationTest t = new AnimationTest();
t.initFrame();
ImageWriter w = t.initWriter();
ImageWriteParam p = w.getDefaultWriteParam();
IIOMetadata streamMetadata = w.getDefaultStreamMetadata(p);
w.prepareWriteSequence(streamMetadata);
for (int i = 0; i < 50; i++) {
BufferedImage f = t.createNextFrame();
ImageTypeSpecifier type = new ImageTypeSpecifier(f);
IIOMetadata m = w.getDefaultImageMetadata(type, p);
w.writeToSequence(new IIOImage(f, null, m), p);
}
w.endWriteSequence();
t.checkAnimation();
} catch (Exception e) {
throw new RuntimeException("Test failed.", e);
}
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class DisableCompressionTest method testFormat.
protected static void testFormat(String format) {
ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next();
if (writer == null) {
throw new RuntimeException("No writer for " + format);
}
ImageWriteParam param = writer.getDefaultWriteParam();
int[] supported_modes = new int[] { ImageWriteParam.MODE_COPY_FROM_METADATA, ImageWriteParam.MODE_DEFAULT, ImageWriteParam.MODE_EXPLICIT };
for (int mode : supported_modes) {
String mode_name = getModeName(mode);
System.out.println("Test mode " + mode_name + "...");
// we know that GIF image writer supports compression
// and supports any compression mode form supportd_modes
// If exception would be thrown here then test failed.
param.setCompressionMode(mode);
// now we are trying to disable compression.
// This operation is not supported because GIF image writer
// does not provide uncompressed output.
// The expected behaviour is that UnsupportedOperationException
// will be thrown here and current compression mode will not be
// changed.
boolean gotException = false;
try {
param.setCompressionMode(ImageWriteParam.MODE_DISABLED);
} catch (UnsupportedOperationException e) {
gotException = true;
} catch (Throwable e) {
throw new RuntimeException("Test failed due to unexpected exception", e);
}
if (!gotException) {
throw new RuntimeException("Test failed.");
}
if (param.getCompressionMode() != mode) {
throw new RuntimeException("Param state was changed.");
}
System.out.println("Test passed.");
}
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class EmbeddedFormatTest method doTest.
public void doTest(String compression, int bi_type) throws IOException {
System.out.println("Test " + compression + " on " + getImageTypeName(bi_type));
BufferedImage src = createTestImage(bi_type);
writer.reset();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
writer.setOutput(ios);
ImageWriteParam wparam = prepareWriteParam(compression);
writer.write(null, new IIOImage(src, null, null), wparam);
ios.flush();
ios.close();
// read result
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ImageInputStream iis = ImageIO.createImageInputStream(bais);
reader.reset();
reader.setInput(iis);
BufferedImage dst = reader.read(0);
checkResult(dst);
}
use of javax.imageio.ImageWriteParam in project jdk8u_jdk by JetBrains.
the class TestCompressionBI_BITFIELDS method prepareWriteParam.
protected ImageWriteParam prepareWriteParam(BufferedImage src) {
ImageWriteParam wparam = writer.getDefaultWriteParam();
wparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
wparam.setCompressionType("BI_BITFIELDS");
return wparam;
}
Aggregations