BufferedImage产生黑色输出 [英] BufferedImage produces black output
本文介绍了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 anImage
, instead useImageIO
to load aBufferedImage
. - Use the buffered image
getType()
as the parameter instead ofBufferedImage.TYPE_..
- Avoid
getScaledInstance(..)
like the plague, but if using it, specifyImage.SCALE_SMOOTH
.
这篇关于BufferedImage产生黑色输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文