[英]Construct a pixel from RGB values
I have RGB values using this: 我有RGB值使用这个:
int pixel = image[x][y];
red = ((pixel & 0xff0000) >> 16);
green = ((pixel & 0x00ff00) >> 8);
blue = (pixel & 0x0000ff);
Then I modify red, green and blue. 然后我修改红色,绿色和蓝色。
How do I construct a new pixel with the new values? 如何使用新值构造新像素?
You want to make sure that red
, green
, blue
are all within 0..255 range. 您需要确保red
, green
, blue
都在0..255范围内。 Then you get them together: 然后你把它们放在一起:
int newPixel =
((int) max(0, min(red, 0xFF)) << 16) |
((int) max(0, min(green, 0xFF)) << 8) |
max(0, min(blue, 0xFF));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.