Hi I am trying to send a BufferedImage I have on my Java application through a tcp socket to an Android Device. I currently get the raster in a byte[] from the BufferedImage and then ship this through a plain OutputStream to the device. This works fine and I get the same byte array on the Android side. When I call Bitmap.decodeByteArray() however, I only get null.
Here is the code I have to send my picture in Java. The image type of the BufferedImage is TYPE_4BYTE_ABGR
byte[] imgBytes = ((DataBufferByte)msg.getImage().getData().getDataBuffer()).getData();
lineBytes = (String.valueOf(imgBytes.length) + '\n').getBytes();
out.write(lineBytes);
out.write(imgBytes);
out.write((int)'\n');
out.flush();
The first thing I write out is the size of the image so I know how big to make the byte[] on Android.
Here's the code I'm trying to use to create the Android Bitmap.
currLine = readLine(in);
int imgSize = Integer.parseInt(currLine);
byte[] imgBytes = new byte[imgSize];
in.read(imgBytes);
BitmapFactory.Options imgOptions = new BitmapFactory.Options();
imgOptions.inPreferredConfig = Bitmap.Config.ARGB_4444;
Bitmap img = BitmapFactory.decodeByteArray(imgBytes, 0, imgSize, imgOptions);
The bytes arrive fine.. They just don't work for the Bitmap.