Solution 1 :
Is the screenshot data from in proper format? Try saving the screenshot to a file and read the raw bytes from the file and send it to the server.
Solution 2 :
I hope I understood your issue correctly, please try this method out.
private static Bitmap getBitmapFromString(String jsonString) {
byte[] decodedString = Base64.decode(jsonString, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
return decodedByte;
}
Problem :
I created socket connection between Server and Android Client and sent Images as byte Array but I can’t find a way to decode byte Array in android.
Every time I try Image = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
I get errors like
SkAndroidCodec:: NewFromStream returned null
unknown bmp header format
Comments
Comment posted by blackapps
You send an image as byte array. Ok. But what kind of image? A bitmap? Don’t do that. Send a jpg or png.
Comment posted by developer.android.com/reference/android/graphics/BitmapFactory
The byte array should contain compressed image data. So no bitmap.
Comment posted by Dhruv Kansara
I ended up converting it to a string and encoding with base64 and vice versa. It worked like a charm. Thanks for all the answers
Comment posted by blackapps
That will not help if the byte array still contains a bitmap.