BufferedImage产生黑色输出 [英] BufferedImage produces black output

查看:255
本文介绍了BufferedImage产生黑色输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BufferedImage由于某种原因在我写缩放图像时会产生黑色输出,但Image会正确缩放。我假设这里有一些绘画组件的问题。谢谢!

BufferedImage for some reason produces black output when I write scaled Image, however Image scales it correctly. I assume here are some problems with painting components. Thank you!

推荐答案

BufferedImage newImage = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB);

如果在其上放置透明的PNG或GIF,透明部分将变为黑色。它应该是:

If putting a PNG or GIF with transparency over it, the transparent parts will become black. It should be:

BufferedImage newImage = new BufferedImage(400, 400, BufferedImage.TYPE_INT_ARGB);

但是,我建议:


  • 如果原始图像为JPEG,则仅保存为JPEG

  • 不使用 ImageIcon 加载 Image ,而是使用 ImageIO 加载 BufferedImage

  • 使用缓冲的图像 getType()作为参数,而不是 BufferedImage.TYPE _ ..

  • 避免 getScaledInstance(..) 喜欢瘟疫,但如果使用它,请指定 Image.SCALE_SMOOTH

  • Only save as JPEG if the original image was JPEG
  • Not using an ImageIcon to load an Image, instead use ImageIO to load a BufferedImage.
  • Use the buffered image getType() as the parameter instead of BufferedImage.TYPE_..
  • Avoid getScaledInstance(..) like the plague, but if using it, specify Image.SCALE_SMOOTH.

这篇关于BufferedImage产生黑色输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆