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);
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);
But then, I recommend:
ImageIcon
to load an Image
, instead use ImageIO
to load a BufferedImage
. getType()
as the parameter instead of BufferedImage.TYPE_..
getScaledInstance(..)
like the plague , but if using it, specify Image.SCALE_SMOOTH
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.