Reputation: 1459
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?
Upvotes: 0
Views: 2921
Reputation: 2769
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.
Upvotes: 4