I have an int array that i obtained by using RobotPeer.getRGBPixels(). I convert it to an byte array to send it over socket by using:
public static byte[] toByteArray(int[] ints){
byte[] bytes = new byte[ints.length * 4];
for (int i = 0; i < ints.length; i++) {
bytes[i * 4] = (byte) (ints[i] & 0xFF);
bytes[i * 4 + 1] = (byte) ((ints[i] & 0xFF00) >> 8);
bytes[i * 4 + 2] = (byte) ((ints[i] & 0xFF0000) >> 16);
bytes[i * 4 + 3] = (byte) ((ints[i] & 0xFF000000) >> 24);
}
return bytes;
}
Problem is: I use this method:
public static int[] toIntArray(byte buf[]) {
int intArr[] = new int[buf.length / 4];
int offset = 0;
for (int i = 0; i < intArr.length; i++) {
intArr[i] = (buf[3 + offset] & 0xFF) | ((buf[2 + offset] & 0xFF) << 8)
| ((buf[1 + offset] & 0xFF) << 16) | ((buf[0 + offset] & 0xFF) << 24);
offset += 4;
}
return intArr;
}
to get back int array. Then i create BufferedImage from it and i get: https://www.dropbox.com/s/p754u3tnivigu70/test.jpeg
Please help me to solve that problem.