Issue
My application receives ByteArray
with .bmp file in it from backend. I need to output that bmp file in ImageView. For Android versions 7+ I create Bitmap
with BitmapFactory.decodeByteArray()
and then do imgView.setImageBitmap()
and it works perfectly fine. But for OS versions 5 and 6 BitmapFactory.decodeByteArray()
returns null
.
I also tried writing bytes to file and creating Bitmap
from file or stream - no good. Creating Drawable
from the file and using file's Uri
for ImageView.setImageUri()
didn't solve the issue either.
Picasso and Glide libraries also don't work.
I would think that Android 5 and 6 can't work with bmp at all, but that just doesn't sound right. Also when I put test image (the same as the one that I receive from server) to res/mipmap
folder I am able to output it to my ImageView.
So my question is what is the solution to that? How do I output .bmp image from ByteArray
or locally saved file to ImageView
on Android 5 and 6?
Solution
So I solved the issue. There was a bug in my bitmap receiving code, so the final ByteArray
didn't contain data for the last image column. Apparently, Android 7+ decoding mechanism ignores this issue and just decodes as much data as possible. But the previous versions of the OS strictly require enough data for full image.
Answered By - 0awawa0
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.