这里有一个类的示例,该类从不同的图像创建动画的gif:
编辑:链接似乎已死。 无论如何,为了清楚起见,这段代码是由Elliot Kroo完成的。
编辑2:感谢您@Marco13
找到WayBackMachine链接。更新了参考!
该类提供以下方法:
class GifSequenceWriter { public GifSequenceWriter( ImageOutputStream outputStream, int imageType, int timeBetweenframesMS, boolean loopContinuously); public void writeToSequence(RenderedImage img); public void close();}
还有一个小例子:
public static void main(String[] args) throws Exception { if (args.length > 1) { // grab the output image type from the first image in the sequence BufferedImage firstImage = ImageIO.read(new File(args[0])); // create a new BufferedOutputStream with the last argument ImageOutputStream output = new FileImageOutputStream(new File(args[args.length - 1])); // create a gif sequence with the type of the first image, 1 second // between frames, which loops continuously GifSequenceWriter writer = new GifSequenceWriter(output, firstImage.getType(), 1, false); // write out the first image to our sequence... writer.writeToSequence(firstImage); for(int i=1; i<args.length-1; i++) { BufferedImage nextImage = ImageIO.read(new File(args[i])); writer.writeToSequence(nextImage); } writer.close(); output.close(); } else { System.out.println( "Usage: java GifSequenceWriter [list of gif files] [output file]"); }}
向Elliot Kroo推荐此代码。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)