3

I can get the r,g,b values using the following functions.

int rgb=bImg.getRGB(i, j);
int r=(rgb>>16) & 0xff; 
int g=(rgb>>8) & 0xff;
int b=(rgb) & 0xff;

Now I do some operations in on those values and want to set the rgb values using the following function

bImg.setRgb(int x,int y,int rgb)

But i do not know how to calculate rgb from R,G,B values.

sayem siam
  • 1,281
  • 3
  • 13
  • 26

1 Answers1

3
int rgb = (r<<16) + (g<<8) + b;

Or

int rgb = (r<<16)  | (g<<8)  | b;

will do the inverse operation and store r , g and b into a single integer as you have decoded.

parapura rajkumar
  • 24,045
  • 1
  • 55
  • 85