[英]BufferedImage produces black output
BufferedImage for some reason produces black output when I write scaled Image, however Image scales it correctly. 当我写缩放图像时,BufferedImage由于某种原因产生黑色输出,但Image会正确缩放它。 I assume here are some problems with painting components.
我假设这里有一些绘画组件的问题。 Thank you!
谢谢!
BufferedImage newImage = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB);
If putting a PNG or GIF with transparency over it, the transparent parts will become black. 如果在其上放置透明的PNG或GIF,透明部分将变为黑色。 It should be:
它应该是:
BufferedImage newImage = new BufferedImage(400, 400, BufferedImage.TYPE_INT_ARGB);
But then, I recommend: 但是,我建议:
ImageIcon
to load an Image
, instead use ImageIO
to load a BufferedImage
. ImageIcon
加载Image
,而是使用ImageIO
加载BufferedImage
。 getType()
as the parameter instead of BufferedImage.TYPE_..
getType()
作为参数而不是BufferedImage.TYPE_..
getScaledInstance(..)
like the plague , but if using it, specify Image.SCALE_SMOOTH
. getScaledInstance(..)
,但如果使用它,请指定Image.SCALE_SMOOTH
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.