本文整理汇总了Java中javax.imageio.ImageWriter.prepareWriteSequence方法的典型用法代码示例。如果您正苦于以下问题:Java ImageWriter.prepareWriteSequence方法的具体用法?Java ImageWriter.prepareWriteSequence怎么用?Java ImageWriter.prepareWriteSequence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.ImageWriter
的用法示例。
在下文中一共展示了ImageWriter.prepareWriteSequence方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createGif
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
/**
* Create the gif and clear down afterwards.
*
* @return the gif byte data
* @throws IOException if the output fails
*/
public byte[] createGif() throws IOException {
try {
ImageOutputStream ios = ImageIO.createImageOutputStream(baos); // N.b. not try with closure because we need to close the stream before returning
ImageWriter iw = ImageIO.getImageWritersByFormatName("gif").next();
iw.setOutput(ios);
iw.prepareWriteSequence(null);
int index = 0;
ImageWriteParam iwp = iw.getDefaultWriteParam();
String frameDelay = String.valueOf(OptionsObject.getInstance().getGifDisplayTimeMillis() / 10L);
log.debug("Frames size: {}, Free memory {}", frames.size(), Runtime.getRuntime().freeMemory());
for (BufferedImage frame : frames) {
IIOMetadata metadata = iw.getDefaultImageMetadata(new ImageTypeSpecifier(frame), iwp);
configureMetaData(metadata, frameDelay, index++);
iw.writeToSequence(new IIOImage(frame, null, metadata), null);
}
iw.endWriteSequence();
ios.close();
return baos.toByteArray();
} finally {
baos = null;
frames = null;
}
}
示例2: createTestImage
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
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");
}
示例3: test
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
private static void test(final ImageWriter writer) throws Exception {
final File file = File.createTempFile("temp", ".img");
file.deleteOnExit();
final FileOutputStream fos = new FileOutputStream(file);
final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
writer.setOutput(ios);
final IIOMetadata data = writer.getDefaultStreamMetadata(null);
if (writer.canWriteSequence()) {
writer.prepareWriteSequence(data);
} else {
try {
writer.prepareWriteSequence(data);
throw new RuntimeException(
"UnsupportedOperationException was not thrown");
} catch (final UnsupportedOperationException ignored) {
// expected
}
}
writer.dispose();
ios.close();
}
示例4: createAnimatedImage
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public void createAnimatedImage(BufferedImage bi, IIOMetadata metadata,
ImageWriter writer, File outputFile) {
try {
fos = new FileOutputStream(outputFile);
ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
System.out.println(ios);
writer.setOutput(ios);
ImageWriteParam param = writer.getDefaultWriteParam();
IIOMetadata streamData = writer.getDefaultStreamMetadata(param);
writer.prepareWriteSequence(streamData);
ImageTypeSpecifier specify = new ImageTypeSpecifier(bi);
IIOMetadata imgData = writer.convertImageMetadata(
(IIOMetadata) metadata, specify, param);
GIFImageMetadata gifData = setAnimationProperties(imgData);
IIOImage iim = new IIOImage(bi, null, gifData);
param.setProgressiveMode(param.MODE_DISABLED);
writer.writeToSequence(iim, param);
writer.endWriteSequence();
ios.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例5: main
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
String format = "GIF";
ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next();
ImageWriteParam param = writer.getDefaultWriteParam();
IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(param);
boolean gotException = false;
try {
writer.prepareWriteSequence(streamMetadata);
} catch (IllegalStateException e) {
gotException = true;
System.out.println("Test passed.");
e.printStackTrace(System.out);
}
if (!gotException) {
throw new RuntimeException("Test failed.");
}
}
示例6: main
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
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);
}
}
示例7: test
import javax.imageio.ImageWriter; //导入方法依赖的package包/类
private static void test(final ImageWriter writer) throws Exception {
try {
file = File.createTempFile("temp", ".img");
fos = new FileOutputStream(file);
final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
writer.setOutput(ios);
final IIOMetadata data = writer.getDefaultStreamMetadata(null);
if (writer.canWriteSequence()) {
writer.prepareWriteSequence(data);
} else {
try {
writer.prepareWriteSequence(data);
throw new RuntimeException(
"UnsupportedOperationException was not thrown");
} catch (final UnsupportedOperationException ignored) {
// expected
}
}
} finally {
writer.dispose();
if (file != null) {
if (fos != null) {
fos.close();
}
Files.delete(file.toPath());
}
}
}
示例8: 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.");
}