Combine the individual color values for the 3 channels (red, green and blue) in one pixel using bitwise operators:
int rgb = (redValue & 0xff) << 16 | (greenValue & 0xff) << 8 | (blueValue & 0xff);
Then call setRGB
with the composed value as parameter:
bufferedImage.setRGB(col, row, rgb);
The bitwise operation sentence can be cumbersome at first sight but it does the following:
Take every channel value and make it 8-bit range based value (0, 255) using the
& 0xff
mask (the formatBufferedImage.TYPE_INT_RGB
expects channels to be 8-bit values)redValue & 0xff
,greenValue & 0xff
,blueValue & 0xff
Accommodates the channel values packing then into one 32 bit integer using the following layout: