use of javax.imageio.stream.ImageOutputStream in project adempiere by adempiere.
the class ScreenShot method createJPEG.
/**
* Create JPEG file from window
* @param window window
* @param fileName optional file name
* @return true if created
*/
public static boolean createJPEG(Window window, String fileName) {
BufferedImage bi = null;
if (window == null || fileName == null)
new IllegalArgumentException("ScreenShot.createJPEG Window os NULL");
// Get File
File file = getJPGFile(window);
if (file == null)
return false;
log.config("File=" + file);
if (file.exists())
file.delete();
// Get Writer
Iterator writers = ImageIO.getImageWritersByFormatName("jpg");
ImageWriter writer = (ImageWriter) writers.next();
if (writer == null) {
log.log(Level.SEVERE, "no ImageWriter");
return false;
}
// Get Image
try {
Thread.sleep(1000);
bi = getImage(window);
} catch (InterruptedException ex) {
log.log(Level.SEVERE, "ex", ex);
}
// Write Image
try {
ImageOutputStream ios = ImageIO.createImageOutputStream(file);
writer.setOutput(ios);
writer.write(bi);
ios.flush();
ios.close();
} catch (IOException ex) {
log.log(Level.SEVERE, "ex", ex);
return false;
}
return true;
}
use of javax.imageio.stream.ImageOutputStream in project jdk8u_jdk by JetBrains.
the class LUTCompareTest method createTestImage.
/* Create test image with two frames:
* 1) with {red, red} palette
* 2) with {blue, red } palette
*/
private static Image createTestImage() throws IOException {
BufferedImage frame1 = createFrame(new int[] { 0xffff0000, 0xffff0000 });
BufferedImage frame2 = createFrame(new int[] { 0xff0000ff, 0xffff0000 });
ImageWriter writer = ImageIO.getImageWritersByFormatName("GIF").next();
ImageOutputStream ios = ImageIO.createImageOutputStream(new File("lut_test.gif"));
ImageWriteParam param = writer.getDefaultWriteParam();
writer.setOutput(ios);
writer.prepareWriteSequence(null);
writer.writeToSequence(new IIOImage(frame1, null, null), param);
writer.writeToSequence(new IIOImage(frame2, null, null), param);
writer.endWriteSequence();
writer.reset();
writer.dispose();
ios.flush();
ios.close();
return Toolkit.getDefaultToolkit().createImage("lut_test.gif");
}
use of javax.imageio.stream.ImageOutputStream in project jdk8u_jdk by JetBrains.
the class CachePermissionsTest method main.
public static void main(String[] args) {
boolean isFileCacheExpected = Boolean.valueOf(args[0]).booleanValue();
System.out.println("Is file cache expected: " + isFileCacheExpected);
ImageIO.setUseCache(true);
System.out.println("java.io.tmpdir is " + System.getProperty("java.io.tmpdir"));
if (args.length > 1) {
String testsrc = System.getProperty("test.src", ".");
String policy = testsrc + File.separator + args[1];
System.out.println("Policy file: " + policy);
System.setProperty("java.security.policy", policy);
System.out.println("Install security manager...");
System.setSecurityManager(new SecurityManager());
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
boolean isFileCache = ios.isCachedFile();
System.out.println("Is file cache used: " + isFileCache);
if (isFileCache != isFileCacheExpected) {
System.out.println("WARNING: file chace usage is not as expected!");
}
System.out.println("Verify data writing...");
for (int i = 0; i < 8192; i++) {
ios.writeInt(i);
}
System.out.println("Verify data reading...");
ios.seek(0L);
for (int i = 0; i < 8192; i++) {
int j = ios.readInt();
if (i != j) {
throw new RuntimeException("Wrong data in the stream " + j + " instead of " + i);
}
}
System.out.println("Verify stream closing...");
ios.close();
} catch (IOException e) {
/*
* Something went wrong?
*/
throw new RuntimeException("Test FAILED.", e);
} catch (SecurityException e) {
/*
* We do not expect security execptions here:
* we there are any security restrition, ImageIO
* should swith to memory-cached streams, instead
* of using file cache.
*/
throw new RuntimeException("Test FAILED.", e);
}
}
use of javax.imageio.stream.ImageOutputStream 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.stream.ImageOutputStream in project jdk8u_jdk by JetBrains.
the class TopDownTest method writeWithCompression.
private static void writeWithCompression(BufferedImage src, String compression) throws IOException {
System.out.println("Compression: " + compression);
ImageWriter writer = ImageIO.getImageWritersByFormatName("BMP").next();
if (writer == null) {
throw new RuntimeException("Test failed: no bmp writer available");
}
File fout = File.createTempFile(compression + "_", ".bmp", new File("."));
ImageOutputStream ios = ImageIO.createImageOutputStream(fout);
writer.setOutput(ios);
BMPImageWriteParam param = (BMPImageWriteParam) writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionType(compression);
param.setTopDown(true);
writer.write(null, new IIOImage(src, null, null), param);
writer.dispose();
ios.flush();
ios.close();
BufferedImage dst = ImageIO.read(fout);
verify(dst);
}
Aggregations