GifSequenceWriter 创建白色 Gif
GifSequenceWriter Creating White Gif
我需要将图像拆分成单独的幻灯片并将它们编译成 .gif,但 .gif 最终变成纯白色。每张幻灯片都是 32x32 像素,它们水平堆叠,中间没有空格。我在我的代码中使用了 class GifSequenceWriter:
/**
* @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
,但我无法弄清楚我做错了什么。
我使用的是具有部分透明度的 .png,这使得所有内容都完全透明。我刚刚删除了修复所有问题的透明度
我需要将图像拆分成单独的幻灯片并将它们编译成 .gif,但 .gif 最终变成纯白色。每张幻灯片都是 32x32 像素,它们水平堆叠,中间没有空格。我在我的代码中使用了 class GifSequenceWriter:
/**
* @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
,但我无法弄清楚我做错了什么。
我使用的是具有部分透明度的 .png,这使得所有内容都完全透明。我刚刚删除了修复所有问题的透明度