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
Re: Alter blue values of a pixel
Quote:
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:
Code:
int setLowestBit(int argb, boolean bit) {
return (argb&-2)|(bit?1:0);
}
kind regards,
Jos (bit fiddler ;-)
Re: Alter blue values of a pixel
Thank You for replying
I might have to change the complete value in some cases based on an input.
Re: Alter blue values of a pixel
Quote:
Originally Posted by
forwardbias
Thank You for replying
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:
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
Re: Alter blue values of a pixel