# Thread: Alter blue values of a pixel

1. Member
Join Date
Mar 2012
Posts
23
Rep Power
0

## Alter blue values of a pixel

Hi Guys
I am doing a project on Steganography.I am at a juncture where I need to alter the blue values of a pixel.I have almost devised an algorithm but it is incomplete.The steps are
1)Obtain the rgb values of the pixel using getRGB and the do the right shifting and bitwise AND-ing with 0xff.
2)We will obtain integer RGB values.Change the blue to the desired value
3)Now obtain the binary equivalent of the value by left shifting and bitwise AND-ing with 0xff.

My question is how do I combine the RGB values so that I can use the setRGB method in BufferedImage.I am unable to bridge the gap.I hope I have been able to express myself clearly.I would welcome any other algorithm.Please help.I will be really grateful

2. ## Re: Alter blue values of a pixel

Originally Posted by forwardbias
Hi Guys
I am doing a project on Steganography.I am at a juncture where I need to alter the blue values of a pixel.I have almost devised an algorithm but it is incomplete.The steps are
1)Obtain the rgb values of the pixel using getRGB and the do the right shifting and bitwise AND-ing with 0xff.
2)We will obtain integer RGB values.Change the blue to the desired value
3)Now obtain the binary equivalent of the value by left shifting and bitwise AND-ing with 0xff.

My question is how do I combine the RGB values so that I can use the setRGB method in BufferedImage.I am unable to bridge the gap.I hope I have been able to express myself clearly.I would welcome any other algorithm.Please help.I will be really grateful
If you ony want to change the lowest bit of the blue value there is no need to unravel the rgb number; the following will do fine:

Java Code:
```int setLowestBit(int argb, boolean bit) {
return (argb&-2)|(bit?1:0);
}```
kind regards,

Jos (bit fiddler ;-)

3. Member
Join Date
Mar 2012
Posts
23
Rep Power
0

## Re: Alter blue values of a pixel

I might have to change the complete value in some cases based on an input.

4. ## Re: Alter blue values of a pixel

Originally Posted by forwardbias
I might have to change the complete value in some cases based on an input.
For the blue component (the least significant byte) of an argb value it's easy:

Java Code:
```int getValue(int argb) { return argb&0xff; }
int setValue(int argb, int val) { argb= (argb&0xffffff00)|val; return argb; }```
Two oneliners, that's all that's needed ;-)

kind regards,

Jos
Last edited by JosAH; 04-13-2012 at 06:35 PM.

5. Member
Join Date
Mar 2012
Posts
23
Rep Power
0

Thank You