Android: problem retrieving bitmap from database

后端 未结 1 1294
一个人的身影
一个人的身影 2020-12-17 03:14

When I\'m retrieving image from the sqlite database my Bitmap object bm return null value can any one help me..?

I found problem in my database..

<
相关标签:
1条回答
  • 2020-12-17 03:44

    Here's how I encode the image before writing to the database:

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    mBitmap.compress(Bitmap.CompressFormat.JPEG, THUMB_QUALITY, outputStream);
    mByteArray = outputStream.toByteArray();  // write this to database as blob
    

    And then decode it like the from Cursor:

    ByteArrayInputStream inputStream = new ByteArrayInputStream(cursor.getBlob(columnIndex));
    Bitmap mBitmap = BitmapFactory.decodeStream(inputStream);
    
    0 讨论(0)
提交回复
热议问题