BufferedImage rotated, change resulting background

南笙酒味 提交于 2019-12-02 03:01:34

You have (at least) two options...

You Could...

Paint the background of the BufferedImage before you paint the rotated image...

public BufferedImage rotateImage(BufferedImage image, double degreesAngle) {    
    int w = image.getWidth();    
    int h = image.getHeight();    
    BufferedImage result = new BufferedImage(w, h, image.getType());  
    Graphics2D g2 = result.createGraphics();  
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, w, h);
    g2.rotate(Math.toRadians(degreesAngle), w/2, h/2);
    g2.drawImage(image,null,0,0);  
    return result;   
}  

You Could...

Paint the area behind the image before you paint it to the panel...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!