0

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 Cursor

  • BitmapFactory.decodeStream(inputStream) returns null

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!

  • 1
    You might want to add how you're storing the blob in the first place. Also, if this is on Android, which I am assuming, tag it as such please. – ci_ Apr 07 '15 at 09:09
  • This might help you http://stackoverflow.com/questions/9357668/how-to-store-image-in-sqlite-database – Daniel Petrov Apr 07 '15 at 10:14

0 Answers0