I want to send an Image (.png or .jpg, I tried both) with an Socket Connection from a server to an Android phone.
I convert the Buffered Image to a byte array via:
Using java Syntax Highlighting
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- ImageIO.write(img, "png", stream);
- return stream.toByteArray();
Parsed in 0.029 seconds, using GeSHi 1.0.8.4
The server has no problems with decoding it again. I suspected that the following would be enough to convert the Byte Array back to an image on the phone:
Using java Syntax Highlighting
- byte[] data = ...
- Bitmap bm = BitmapFactory.decodeByteArray(data, 0, data.length);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
But unfortunately the BitmapFactory returns null, indicading that the byte array could not be decoded.
I'm clueless here, I suspect the decoding to be the problem here, but of course it could also be the socket connection.
That's why I wanted to ask, if someone can confirm that a byte array produced by ImageIO/ByteArrayOutputStream can be decoded with BitmapFactory.decodeByteArray or if someone knows a better way of doing this.
Thx in advance


