ImageIO:gif 到 jpeg 问题 ->图像变成粉红色
我正在尝试使用 imageIO 将 gif 转换为 jpeg,但生成的图像是粉红色的...有人可以帮忙吗?
public byte[] convert(byte[] bytes)
throws Exception {
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
BufferedImage bufferedImage = ImageIO.read(inputStream);
ByteArrayOutputStream osByteArray = new ByteArrayOutputStream();
ImageOutputStream outputStream = ImageIO.createImageOutputStream(osByteArray);
ImageIO.write(bufferedImage, "jpg", outputStream);
outputStream.flush();
outputStream.close();
return osByteArray.toByteArray();
}
I'm trying to convert a gif to a jpeg using imageIO but the resulting image is pink... Anyone can help?
public byte[] convert(byte[] bytes)
throws Exception {
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
BufferedImage bufferedImage = ImageIO.read(inputStream);
ByteArrayOutputStream osByteArray = new ByteArrayOutputStream();
ImageOutputStream outputStream = ImageIO.createImageOutputStream(osByteArray);
ImageIO.write(bufferedImage, "jpg", outputStream);
outputStream.flush();
outputStream.close();
return osByteArray.toByteArray();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许,粉红色被定义为 gif 图像的透明度颜色。如果是这样,下面的示例可能会起作用。基本上,创建一个新图像,并将“背景颜色”显式设置为传入的任何内容。
看起来像 这可能相关。
Perhaps, pink is defined as the transparency color for the gif image. If so, the following example might work. Basically, a new image is created and the "backgound color" is explicitly set to whatever is passed in.
Looks like this might be related.