0

I want to know if Bitmap's memory and byte[] have connection? And the jpeg file is 28kb but when I load the image file to bitmap then I get the bitmap's bytes it's 200 * 1204 byte. Why it is?

If I change the bitmap(A) and compress it to byte[](the byte[] length is 280 * 1024 byte) and then create bitmap(B) from byte[] final, I get the byte[] from the bitmap(B) but the byte[]. Length is not 280 * 1024 byte - why? I can't find any article for this. Who can explain this? Thanks.

 byte[] finalData = bitmapUtil.getScaledImageBytes(originBitmap,BitmapUtil.MAX_IMAGE_DATA_LENGTH); (finalData.length 280 * 1024)
originBitmap = BitmapFactory.decodeByteArray(finalData,0,finalData.length);
byte[] now = bitmapUtil.bitmap2Byte(originBitmap); (now.length 400 * 1024)

public byte[] bitmap2Byte(Bitmap bitmap) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG,100,bos);
    byte[] data = bos.toByteArray();
    bos.close();
    return data;
}
yakobom
  • 2,681
  • 1
  • 25
  • 33
empt
  • 133
  • 1
  • 10

1 Answers1

0

I think that once you load the image to a Bitmap object, some format / compression properties might be the cause for the change in size you see. If you compress the bitmap, you change the data - so the byte array is supposed to be of a different length.

Regarding some reading, it is not exactly what you wanted but perhaps these can help:

Android - Reduce image file size

Loading Large Bitmaps Efficiently

Strange out of memory issue while loading an image to a Bitmap object

yakobom
  • 2,681
  • 1
  • 25
  • 33