I want to store image in SQLite DataBase
.
I tried to store it using BLOB
and String
, in both cases it store the
image and can retrieve it but when i convert it to Bitmap
using
BitmapFactory.decodeByteArray(...)
it return null.
I have used this code, but it returns null
Bitmap bitmap = BitmapFactory.decodeByteArray(blob, 0, blob.length);
The answer of Uttam didnt work for me. I just got null when I do:
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata, 0, bitmapdata.length);
In my case, bitmapdata only has the buffer of the pixels, so it is imposible for the function decodeByteArray to guess which the width, the height and the color bits use. So I tried this and it worked:
//Create bitmap with width, height, and 4 bytes color (RGBA)
Bitmap bmp = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_8888);
ByteBuffer buffer = ByteBuffer.wrap(bitmapdata);
bmp.copyPixelsFromBuffer(buffer);
Check https://developer.android.com/reference/android/graphics/Bitmap.Config.html for different color options
Source: Stackoverflow.com