Get a blob image and convert this image to a bitmap

I get the image from the database in blob format. I want to convert it to a Bitmap image. The code that I used to convert the bitmap to Blob is placed below. but please tell me how to cancel it. ???

ByteArrayOutputStream boas = new ByteArrayOutputStream(); btmap.compress(Bitmap.CompressFormat.JPEG, 100, boas ); //bm is the bitmap object byte[] byteArrayImage = boas .toByteArray(); String encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT); 
+5
source share
2 answers

It will work

 byte[] byteArray = DBcursor.getBlob(columnIndex); Bitmap bm = BitmapFactory.decodeByteArray(byteArray, 0 ,byteArray.length); 
+25
source

Why not create a helper method :)

 public static Bitmap getBitmapFromBytes(byte[] bytes) { if (bytes != null) { return BitmapFactory.decodeByteArray(bytes, 0 ,bytes.length); } return null; } 
0
source

All Articles