1

I am converting bitmap from bytes array using following code:

InputStream is = getInputStreamFromURL(urlStr);
if (is != null) {
    ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
    byte[] data = new byte[1024 * 10];
    int len;
    while ((len = is.read(data, 0, data.length)) != -1) {
        os.write(data, 0, len);
    }
    is.close();
    byte[] imageArray = os.toByteArray();
    Log.d(TAG, "imageArray.length: "+imageArray.length); // Size 72.1 KB
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;
    bitmap = BitmapFactory.decodeByteArray(imageArray, 0, imageArray.length/*, options*/);
    Log.d(TAG, "getByteCount: "+bitmap.getByteCount()); // Size 1.7 MB
}

But after converting bitmap from byte array its size increased (dimensions are still same):

Original image size = 72.1 KB

After converting it to bitmap = 1.7 MB.

Can anyone help me? Why it happens or what is wrong in code?

K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33
Prince H
  • 31
  • 1
  • 1
  • 2
  • simply follow something [like this](http://stackoverflow.com/questions/10513976/how-to-convert-image-into-byte-array-and-byte-array-to-base64-string-in-android), don't define hard coded values `1024 * 10` – Pavneet_Singh Dec 05 '16 at 05:22
  • Are you sure that the image indicated by urlStr is a bitmap? If it's a jpeg or other compressed format then you are downloading that format and converting it to the uncompressed bmp format which is [BPP * x * y] in size where BPP is bits per pixel. – Monza Dec 05 '16 at 06:15
  • @Monza Images are in jpeg format. How can I compress it? – Prince H Dec 05 '16 at 06:21
  • The bitmap object may be able to save out to disk in another format. Failing that, bmp is a fairly baseline format that should communicate easily with the standard jpeg class etc. Bmp is a fairly lossless fundamental format but it is uncompressed and huge! – Monza Dec 05 '16 at 06:56

0 Answers0