Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Blob image and convert that image into Bitmap image

I am getting image from database in blob format. i want to convert it into Bitmap image.the code i used to convert bitmap to Blob is put below.but please tell me how to reverse 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);
like image 439
Mikin Patel Avatar asked Apr 06 '13 10:04

Mikin Patel


2 Answers

This will work

byte[] byteArray = DBcursor.getBlob(columnIndex);  

Bitmap bm = BitmapFactory.decodeByteArray(byteArray, 0 ,byteArray.length);
like image 187
Sankar V Avatar answered Sep 18 '22 10:09

Sankar V


You can use this simple static function, It is super easy to implement and reuse :)

public static Bitmap getBitmapFromBytes(byte[] bytes) {
        if (bytes != null) {
            return BitmapFactory.decodeByteArray(bytes, 0 ,bytes.length);
        }
        return null;
 }
like image 34
Avineet Gupta Avatar answered Sep 21 '22 10:09

Avineet Gupta