I have a few days with the same problem, I am making an application in which I need to save images in SQLite
, until then good.
The problem is when trying to recover, attached my code:
recuperarImagen = db.rawQuery("SELECT fotoPerfil FROM perfil WHERE _id = 1", null);
if(recuperarImagen.moveToFirst()){
byte[] blob = recuperarImagen.getBlob(0);
ByteArrayInputStream inputStream = new ByteArrayInputStream(blob);
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
imagenPersonal.setImageBitmap(bitmap);
}
recuperarImagen
is the CursorBitmapFactory.decodeStream(inputStream)
returnsnull
To store the image I use this method:
public static byte[] getBitmapAsByteArray(Bitmap bitmap) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 0, outputStream);
return outputStream.toByteArray();
}
If anyone can help I would be very grateful, Thanks in advance!