Change the alpha value of a BufferedImage?

后端 未结 6 1720
清酒与你
清酒与你 2020-12-11 04:21

How do I change the global alpha value of a BufferedImage in Java? (I.E. make every pixel in the image that has a alpha value of 100 have a alpha value of 80)

6条回答
  •  没有蜡笔的小新
    2020-12-11 04:33

    @Neil Coffey: Thanks, I've been looking for this too; however, Your code didn't work very well for me (white background became black).

    I coded something like this and it works perfectly:

    public void setAlpha(byte alpha) {       
        alpha %= 0xff; 
        for (int cx=0;cx

    Where obj_img is BufferedImage.TYPE_INT_ARGB.

    I change alpha with setAlpha((byte)125); alpha range is now 0-255.

    Hope someone finds this useful.

提交回复
热议问题