0

I am trying to convert byte array to bitmap to display an image in android app. But while converting it is returning the null value. I have used the following code:

operations = new DataBaseOperations();
byte image[] = operations.fetchimage(); // gets byte array from the database        
BitmapFactory.Options options = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeByteArray(image, 0, image.length, options);

Herebitmap is null, why?

Adam Stelmaszczyk
  • 19,333
  • 4
  • 67
  • 107
Vinit ...
  • 1,328
  • 9
  • 34
  • 62

1 Answers1

4

Try this link. It will solve your problem

How to convert byte array to Bitmap

or just check this code

Bitmap bitmap = BitmapFactory.decodeFile("/path/images.jpg");
ByteArrayOutputStream blob = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, blob);
byte[] bitmapdata = blob.toByteArray();

//if bitmapdata is the byte array then getting bitmap goes like this

Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata , 0, bitmapdata .length);

Returns The decoded bitmap, or null if the image could not be decode.

Community
  • 1
  • 1
Ameer
  • 2,677
  • 1
  • 26
  • 42