编程语言
首页 > 编程语言> > java – ImageIO.write没有保存为gif,但适用于jpgs和pngs?

java – ImageIO.write没有保存为gif,但适用于jpgs和pngs?

作者:互联网

我怀疑这里的解决方案可能很简单,但我很难过……

// Create the buffered image.
BufferedImage bufferedImage = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);

// fill image data (works fine)
ImageIO.write(bufferedImage, "JPG", f1); // works fine
ImageIO.write(bufferedImage, "PNG", f2); // works fine
ImageIO.write(bufferedImage, "GIF", f3); // this returns false, creates a broken gif file, but fires no exceptions

ImageIO.write()不能用于GIF吗?这是对gif作为专有Compuserve事物的某种回归吗?或者我只是愚蠢(我猜它是最后一个:))

解决方法:

http://java.sun.com/javase/6/docs/api/javax/imageio/package-summary.html#gif_plugin_notes

请注意,GIF只能存储256种颜色.

标签:java,javax-imageio
来源: https://codeday.me/bug/20190611/1215072.html