本文整理汇总了Java中javax.imageio.ImageWriter.addIIOWriteProgressListener方法的典型用法代码示例。如果您正苦于以下问题:Java ImageWriter.addIIOWriteProgressListener方法的具体用法?Java ImageWriter.addIIOWriteProgressListener怎么用?Java ImageWriter.addIIOWriteProgressListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.ImageWriter
的用法示例。
在下文中一共展示了ImageWriter.addIIOWriteProgressListener方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTest
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public void doTest() {
try {
System.out.println("Progress test for " + compression_type);
BufferedImage bi = new BufferedImage(20, 300, BufferedImage.TYPE_INT_RGB);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
Iterator iter = ImageIO.getImageWritersByFormatName(format);
if (!iter.hasNext()) {
throw new RuntimeException("No available writer for " + format);
}
ImageWriter writer = (ImageWriter)iter.next();
writer.setOutput(ios);
writer.addIIOWriteProgressListener(listener);
IIOImage iio_img = new IIOImage(bi, null, null);
ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionType(compression_type);
writer.write(null, iio_img, param);
if (!listener.isTestPassed) {
throw new RuntimeException("Test for " + compression_type + " does not finish correctly!");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例2: test
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
private void test(final ImageWriter writer) throws IOException {
// Image initialization
final BufferedImage imageWrite = new BufferedImage(WIDTH, HEIGHT,
TYPE_BYTE_BINARY);
final Graphics2D g = imageWrite.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, WIDTH, HEIGHT);
g.dispose();
// File initialization
final File file = File.createTempFile("temp", ".img");
file.deleteOnExit();
final FileOutputStream fos = new SkipWriteOnAbortOutputStream(file);
final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
writer.setOutput(ios);
writer.addIIOWriteProgressListener(this);
// This write will be aborted, and file will not be touched
writer.write(imageWrite);
if (!isStartedCalled) {
throw new RuntimeException("Started should be called");
}
if (!isProgressCalled) {
throw new RuntimeException("Progress should be called");
}
if (!isAbortCalled) {
throw new RuntimeException("Abort should be called");
}
if (isCompleteCalled) {
throw new RuntimeException("Complete should not be called");
}
// Flush aborted data
ios.flush();
// This write should be completed successfully and the file should
// contain correct image data.
abortFlag = false;
isAbortCalled = false;
isCompleteCalled = false;
isProgressCalled = false;
isStartedCalled = false;
writer.write(imageWrite);
if (!isStartedCalled) {
throw new RuntimeException("Started should be called");
}
if (!isProgressCalled) {
throw new RuntimeException("Progress should be called");
}
if (isAbortCalled) {
throw new RuntimeException("Abort should not be called");
}
if (!isCompleteCalled) {
throw new RuntimeException("Complete should be called");
}
writer.dispose();
ios.close();
// Validates content of the file.
final BufferedImage imageRead = ImageIO.read(file);
for (int x = 0; x < WIDTH; ++x) {
for (int y = 0; y < HEIGHT; ++y) {
if (imageRead.getRGB(x, y) != imageWrite.getRGB(x, y)) {
throw new RuntimeException("Test failed.");
}
}
}
}
示例3: WriteAbortTest
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public WriteAbortTest(String format) throws Exception {
try {
System.out.println("Test for format " + format);
bimg = new BufferedImage(width, heght,
BufferedImage.TYPE_INT_RGB);
Graphics2D g = bimg.createGraphics();
g.setColor(srccolor);
g.fillRect(0, 0, width, heght);
g.dispose();
file = File.createTempFile("src_", "." + format, new File("."));
ImageInputStream ios = ImageIO.createImageOutputStream(file);
ImageWriter writer =
ImageIO.getImageWritersByFormatName(format).next();
writer.setOutput(ios);
writer.addIIOWriteProgressListener(this);
// Abort writing in IIOWriteProgressListener.imageStarted().
startAbort = true;
writer.write(bimg);
startAbort = false;
// Abort writing in IIOWriteProgressListener.imageProgress().
progressAbort = true;
writer.write(bimg);
progressAbort = false;
ios.close();
/*
* All abort requests from imageStarted,imageProgress
* from IIOWriteProgressListener should be reached
* otherwise throw RuntimeException.
*/
if (!(startAborted
&& progressAborted)) {
throw new RuntimeException("All IIOWriteProgressListener abort"
+ " requests are not processed for format "
+ format);
}
} finally {
Files.delete(file.toPath());
}
}
示例4: doTest
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void doTest(boolean writeSequence) throws IOException {
String format = "GIF";
ImageWriter writer =
ImageIO.getImageWritersByFormatName(format).next();
if (writer == null) {
throw new RuntimeException("No writer available for " + format);
}
BufferedImage img = createTestImage();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
writer.setOutput(ios);
WriterReuseTest t = new WriterReuseTest();
writer.addIIOWriteProgressListener(t);
ImageWriteParam param = writer.getDefaultWriteParam();
IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(param);
IIOImage iioImg = new IIOImage(img, null, null);
if (writeSequence) {
writer.prepareWriteSequence(streamMetadata);
writer.writeToSequence(iioImg, param);
} else {
writer.write(img);
}
if (!t.isWritingAborted || t.isWritingCompleted) {
throw new RuntimeException("Test failed.");
}
t.reset();
// next attempt after abort
ImageOutputStream ios2 =
ImageIO.createImageOutputStream(new ByteArrayOutputStream());
writer.setOutput(ios2);
if (writeSequence) {
writer.writeToSequence(iioImg, param);
} else {
writer.write(img);
}
if (t.isWritingAborted || !t.isWritingCompleted) {
throw new RuntimeException("Test failed.");
}
System.out.println("Test passed.");
}
示例5: test
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
private void test(final ImageWriter writer) throws IOException {
try {
// Image initialization
final BufferedImage imageWrite =
new BufferedImage(WIDTH, HEIGHT, TYPE_BYTE_BINARY);
final Graphics2D g = imageWrite.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, WIDTH, HEIGHT);
g.dispose();
// File initialization
file = File.createTempFile("temp", ".img");
fos = new SkipWriteOnAbortOutputStream(file);
final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
writer.setOutput(ios);
writer.addIIOWriteProgressListener(this);
// This write will be aborted, and file will not be touched
writer.write(imageWrite);
if (!isStartedCalled) {
throw new RuntimeException("Started should be called");
}
if (!isProgressCalled) {
throw new RuntimeException("Progress should be called");
}
if (!isAbortCalled) {
throw new RuntimeException("Abort should be called");
}
if (isCompleteCalled) {
throw new RuntimeException("Complete should not be called");
}
// Flush aborted data
ios.flush();
/*
* This write should be completed successfully and the file should
* contain correct image data.
*/
abortFlag = false;
isAbortCalled = false;
isCompleteCalled = false;
isProgressCalled = false;
isStartedCalled = false;
writer.write(imageWrite);
if (!isStartedCalled) {
throw new RuntimeException("Started should be called");
}
if (!isProgressCalled) {
throw new RuntimeException("Progress should be called");
}
if (isAbortCalled) {
throw new RuntimeException("Abort should not be called");
}
if (!isCompleteCalled) {
throw new RuntimeException("Complete should be called");
}
ios.close();
// Validates content of the file.
final BufferedImage imageRead = ImageIO.read(file);
for (int x = 0; x < WIDTH; ++x) {
for (int y = 0; y < HEIGHT; ++y) {
if (imageRead.getRGB(x, y) != imageWrite.getRGB(x, y)) {
throw new RuntimeException("Test failed.");
}
}
}
} finally {
writer.dispose();
if (file != null) {
if (fos != null) {
fos.close();
}
Files.delete(file.toPath());
}
}
}