0
我需要將圖像拆分爲單獨的幻燈片並將它們編譯成.gif文件,但是.gif最終變成純白色。每張幻燈片都是32x32像素,並且它們水平堆疊,它們之間沒有空格。我使用了類GifSequenceWriter我的代碼:GifSequenceWriter創建白色Gif
/**
* @param args the command line arguments
* @throws java.io.IOException
*/
public static void main(String[] args) throws IOException {
String image = "Image.png";
BufferedImage entireSelection = ImageIO.read(new File(image));
int numOfSlides = entireSelection.getHeight()/32;
BufferedImage[] slides = new BufferedImage[numOfSlides];
for(int i = 0; i<numOfSlides; i++){
slides[i] = entireSelection.getSubimage(0,i*32, 32, 32);
}
createGif(slides);
}
private static void createGif(BufferedImage[] slides) throws IOException {
ImageOutputStream output = new FileImageOutputStream(new File("FinalGif.gif"));
GifSequenceWriter writer = new GifSequenceWriter(output, slides[0].getType() ,1,false);
for (BufferedImage slide : slides) {
writer.writeToSequence(slide);
}
writer.close();
output.close();
}
我已經閱讀了如何使用Writer
,我想不出什麼我做錯了。