I get a byte array with nokia3230'camera.when I draw image with drawRGB function , I find color is error.

public int[] rgb2gray(byte[] bid, int offset, int x, int y, int w, int h) {
int i = 0, f = x+y*width , n , m , j = 0 , r , g , b;
int[] tmp = new int[w*h];
for(n = 0 ; n < h ; n++){
i=f*3+offset;
for(m=0;m<w;m++){
b = (bid[i]) & 0xFF;
g = (bid[i++]) & 0xFF;
r = (bid[i++]) & 0xFF;
tmp[j] = (r<<16|g<<8|b);
i++;
j++;
}
f+=width;
}
return tmp;
}