Java BufferedImage saves with unwanted background color

时光怂恿深爱的人放手 提交于 2019-12-05 06:43:17

setBackground() only set the Color that is used to clear the image, it does not actually clear the image. Call Graphics.clearRect(int,int,int,int) after setBackground(). Like so:

//*create the image
this.img = new BufferedImage( (int)availWidth, (int)availHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D drawer = img.createGraphics() ;
drawer.setBackground(Color.WHITE);
drawer.clearRect(0,0,(int)availWidth,(int)availHeight);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!