简体   繁体   English

BufferedImage产生黑色输出

[英]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: 但是,我建议:

  • Only save as JPEG if the original image was JPEG 如果原始图像为JPEG,则仅保存为JPEG
  • Not using an ImageIcon to load an Image , instead use ImageIO to load a BufferedImage . 不使用ImageIcon加载Image ,而是使用ImageIO加载BufferedImage
  • Use the buffered image getType() as the parameter instead of BufferedImage.TYPE_.. 使用缓冲的图像getType()作为参数而不是BufferedImage.TYPE_..
  • Avoid getScaledInstance(..) like the plague , but if using it, specify Image.SCALE_SMOOTH . 避免像瘟疫一样使用getScaledInstance(..) ,但如果使用它,请指定Image.SCALE_SMOOTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM