Java: Filling a BufferedImage with transparent pixels

后端 未结 6 723
无人共我
无人共我 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:39

    If you cast the Graphics object to a Graphics2D object, you can set a Composite object thru

    AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f);
    Graphics2D g2d = (Graphics2D) image.getGraphics();
    g2d.setComposite(composite);
    g2d.setColor(new Color(0, 0, 0, 0));
    g2d.fillRect(0, 0, 10, 10);
    

提交回复
热议问题