0

I'm reading an image from my phone storage. Among other things, I want to get the size (size in storage, not dimens) of that image.

I know that there are many questions about the topic like:

How to get the size of an image in Android?

how to check image size less then 100kb android

Is there any way to get the storage size of a Bitmap?

...

But none of those gives me the correct size of the image.

Having the imageUri, I convert it to a bitmap as follows:

Bitmap bitmap = MediaStore.Images.Media.getBitmap(activity.getContentResolver(), imageUri);

And then I try:

bitmap.getByteCount()

For a specific image, that I know that it is 1.20MB, the line above returns the value of 9216000. Since it is in Bytes, dividing it by 1024 * 1024, will return 8.78MB.

It clearly doesn't correspond to the real size.

Has anyone else experienced the same trouble?

Notes:

  1. The solutions should only consider that the size should be extracted from the Bitmap object (not File or something else...)

  2. Tried with png and jpg images

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
user677767
  • 203
  • 3
  • 10
  • Maybe I found a answer for you. This has been asked already. https://stackoverflow.com/a/31694333/8301375 – Traendy Oct 11 '19 at 16:31
  • `I want to get the size (size in storage, not dimens) of that image.`. It looks as if you want to know the filesize of the file in storage. `The solutions should only consider that the size should be extracted from the Bitmap object` Well that is something quite differen and not according to what you said first. – blackapps Oct 11 '19 at 20:53

0 Answers0