0

I'm trying to do a camera application with image processing. Here I tried to convert the image (byte array) to bitmap, but

BitmapFactory.decodeByteArray 

is returning null everytime

this is my code :

        Log.e("test -> arry byte = ", String.valueOf(byteArray));
        Log.e("byteArray.length = ", String.valueOf(byteArray.length));
        Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
        Log.e("bitmap ici ->>> ", String.valueOf(bmp));

and the following stack trace :

enter image description here

Anyone has an idea ?

F4Ke
  • 1,631
  • 1
  • 20
  • 49
  • Possible duplicate of [Why does BitmapFactory.decodeByteArray return null?](http://stackoverflow.com/questions/6520745/why-does-bitmapfactory-decodebytearray-return-null) – Alok Gupta Mar 18 '16 at 09:13
  • Can you post your code showing how you get the byte array? In all likelihood it is not a valid image. – rlay3 Mar 18 '16 at 09:30

1 Answers1

0
Bitmap bitmap = BitmapFactory.decodeFile("/path/images/image.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);
Amit Ranjan
  • 567
  • 2
  • 11