1
votes

I have RGB values using this:

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?

1
To reconstruct the pixel's value, just do the opposite. What have you tried so far that isn't working?Cory Nelson

1 Answers

3
votes

You want to make sure that red, green, blue are all within 0..255 range. 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));