标签:gif解析 示例 源码
package com.image.util;
import java.io.File;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.FileImageOutputStream;
import com.sun.imageio.plugins.gif.*;
public class TestMain {
@SuppressWarnings("restriction")
public static void main(String[] args) throws Exception {
File file = new File("d:\\xx.gif");
FileImageInputStream in = new FileImageInputStream(file);
//GIFImageReader reader = null;
ImageReaderSpi readerSpi = new GIFImageReaderSpi();
//readerSpi.canDecodeInput(in);
GIFImageReader gifReader = (GIFImageReader) readerSpi.createReaderInstance();
gifReader.setInput(in);
int num = gifReader.getNumImages(true);
gifReader.getNumImages(true);
System.out.println(num);
ImageWriterSpi writerSpi = new GIFImageWriterSpi();
GIFImageWriter writer = (GIFImageWriter) writerSpi.createWriterInstance();
for (int i = 0; i < num; i++) {
File newfile = new File("d:\\mygif"+i+".jpg");
FileImageOutputStream out = new FileImageOutputStream(newfile);
writer.setOutput(out);
writer.write(gifReader.read(i));
out.close();
}
}
}
标签:gif解析 示例 源码
原文地址:http://2240844.blog.51cto.com/2230844/1553170