Set BufferedImage to be a color in Java

前端 未结 5 981
既然无缘
既然无缘 2021-01-07 19:52

I need to create a rectangular BufferedImage with a specified background color, draw some pattern on the background and save it to file. I don\'t know how to cr

5条回答
  •  轮回少年
    2021-01-07 20:22

    Use this:

    BufferedImage bi = new BufferedImage(width, height,
                    BufferedImage.TYPE_INT_ARGB);
    Graphics2D ig2 = bi.createGraphics();
    
    ig2.setBackground(Color.WHITE);
    ig2.clearRect(0, 0, width, height);
    

提交回复
热议问题