package com.p_w_picpath.util;


import java.io.File;


import javax.p_w_picpathio.spi.ImageReaderSpi;

import javax.p_w_picpathio.spi.ImageWriterSpi;

import javax.p_w_picpathio.stream.FileImageInputStream;

import javax.p_w_picpathio.stream.FileImageOutputStream;


import com.sun.p_w_picpathio.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();

}

}

}