簡體   English   中英

GifSequenceWriter創建白色Gif

[英]GifSequenceWriter Creating White Gif

我需要將圖像拆分為單獨的幻燈片,然后將其編譯為.gif,但是.gif最終變成純白色。 每張幻燈片均為32x32像素,它們水平堆疊,彼此之間沒有空格。 我在代碼中使用了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具有部分透明性,可以使所有內容完全透明。 我只是刪除了固定所有內容的透明性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM