4

How can we convert bitmap image to byte array in Android without compressing the image? Image to byte array in Android:

 Bitmap photo = (Bitmap) data.getExtras().get("data");
 img_view.setImageBitmap(photo);
 Bitmap resizedImage = Bitmap.createScaledBitmap(photo,512,512 , true);
 ByteArrayOutputStream bos = new ByteArrayOutputStream(photo.getWidth()*photo.getHeight());
 resizedImage.compress(Bitmap.CompressFormat.PNG,100, bos);
 bArray = bos.toByteArray();

Set image size between 300 to 400 kb.

Robert
  • 10,403
  • 14
  • 67
  • 117
Bhavani PK
  • 61
  • 3
  • What data format are you expecting the `byte[]` to be in? Your current code is using PNG, which uses lossless compression. What is your specific concern regarding compression? – CommonsWare May 03 '16 at 13:51

0 Answers0