根据RGB值构造像素

时间:2014-02-14 15:08:48

标签: c++ image image-processing pixel

我使用RGB值:

int pixel = image[x][y];

red = ((pixel & 0xff0000) >> 16);
green = ((pixel & 0x00ff00) >> 8);
blue = (pixel & 0x0000ff);

然后我修改红色,绿色和蓝色。

如何使用新值构建新像素?

1 个答案:

答案 0 :(得分:3)

您希望确保redgreenblue都在0..255范围内。然后你把它们放在一起:

int newPixel = 
  ((int) max(0, min(red, 0xFF)) << 16) |
  ((int) max(0, min(green, 0xFF)) << 8) |
  max(0, min(blue, 0xFF));