Java BufferedImage getting red, green and blue individually

前端 未结 4 1234
时光取名叫无心
时光取名叫无心 2020-11-27 02:23

The getRGB() method returns a single int. How can I get individually the red, green and blue colors all as the values between 0 and 255?

4条回答
  •  無奈伤痛
    2020-11-27 03:22

    You'll need some basic binary arithmetic to split it up:

    int blue = rgb & 0xFF;
    int green = (rgb >> 8) & 0xFF;
    int red = (rgb >> 16) & 0xFF;
    

    (Or possibly the other way round, I honestly can't remember and the documentation isn't giving me an instant answer)

提交回复
热议问题