码迷,mamicode.com
首页 > 编程语言 > 详细

java将gif动态图片分开展示源代码简单示例

时间:2014-09-16 12:48:11      阅读:227      评论:0      收藏:0      [点我收藏+]

标签: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();

}

}

}


java将gif动态图片分开展示源代码简单示例

标签:gif解析 示例 源码

原文地址:http://2240844.blog.51cto.com/2230844/1553170

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!