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:
The solutions should only consider that the size should be extracted from the
Bitmap
object (notFile
or something else...)Tried with
png
andjpg
images