Java: Filling a BufferedImage with transparent pixels

后端 未结 6 736
无人共我
无人共我 2020-11-30 06:46

I have an off-screen BufferedImage, constructed with the type BufferedImage.TYPE_INT_ARGB. It can contain anything, and I\'m looking for a way to (fairly effic

6条回答
  •  死守一世寂寞
    2020-11-30 07:14

    After you clear the background with the CLEAR composite, you need to set it back to SRC_OVER to draw normally again. ex:

    //clear
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR));
    g2.fillRect(0,0,256,256);
    
    //reset composite
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
    //draw
    g2.setPaint(Color.RED);
    g2.fillOval(50,50,100,100);
    

提交回复
热议问题