I saw this example here where that program embeds a text message into the LSB of the Alpha byte of a pixel but I don't trully understand everything .How can I embed the information I want only in the LSB of the Red byte or the Blue byte or the Green one from a pixel ?
Here are the functions where I think I should work on(so you don't have to go to the site):
private void embedInteger(BufferedImage img,int n,int start,int storageBit){
int maxX=img.getWidth(),maxY=img.getHeight(),startX=start/maxY,startY=start-startX*maxY,count=0;
for(int i=startX;i<maxX && count<32;i++){
for(int j=startY;j<maxY && count<32;j++){
int rgb=img.getRGB(i, j),bit=getBitValue(n,count);
rgb=setBitValue(rgb,storageBit,bit);
img.setRGB(i,j,rgb);
count++;
}
}
}
private void embedByte(BufferedImage img,byte b,int start,int storageBit){
int maxX=img.getWidth(),maxY=img.getHeight(),startX=start/maxY,startY=start-startX*maxY,count=0;
for(int i=startX;i<maxX && count<8;i++){
for(int j=startY;j<maxY && count<8;j++){
int rgb=img.getRGB(i,j),bit=getBitValue(b,count);
rgb=setBitValue(rgb,storageBit,bit);
img.setRGB(i,j,rgb);
count++;
}
}
}
private int getBitValue(int n,int location){
int v= n & (int) Math.round(Math.pow(2, location));
return v==0?0:1;
}
private int setBitValue(int n,int location,int bit){
int toggle = (int)Math.pow(2, location),bv=getBitValue(n,location);
if(bv==bit)
return n;
if(bv==0&&bit==1)
n |= toggle;
else if(bv==1 && bit==0)
n^=toggle;
return n;
}