On Nov 14, 3:31*pm, Stefan Rybacki <noem...@noemail.foobar> wrote:
> you could just extract the r,g,b and a byte values from the int value.
hi,
thanks for the reply.
i wrote the following code
int pixel=...
byte a=(byte)(pixel>>24);
byte r=(byte)((pixel>>16)&255);
byte g=(byte)((pixel>>

&255);
byte b=(byte)(pixel & 255);
System.out.println("a="+a+"\nr="+r+"\ng="+g+"\nb=" +b);
Also I tried the byteValue() method in class Integer.
Integer in=new Integer(pixel);
byte byteval=in.byteValue();
System.out.println("byteval="+byteval);
This is what i am getting for different values of pixel.
1) pixel=-5334383
a=-1, r=-82, g=-102, b=-111
byteval=-111
2) pixel=-10526881
a=-1, r=95, g=95, b=95
byteval=95
3) pixel=-11192268
a=-1, r=85, g=56, b=52
byteval=52
It seems that the byteVal() always returns the 'b' component .Is there
any particular reason for that?
Also,if i am to create a byte[] to represent the image should i make
byte[] of length=3*number of pixels in the image so as to put r,g,b
byte values of first pixel in the first 3 byte[] cells and so on? I
need to pass that byte[] to another application so that it can be
encrypted and later used to recreate an image.
Is there something wrong in this approach?
thanks
eric