codeKiller
codeKiller

Reputation: 5739

Get image file size from height and width values

According to this answer here, it is possible to read an image height and width without loading the whole image into memory.

There is a sentence bit further down in the answer telling that

bitmap of approximately 512x384. Loading this into memory uses 0.75MB rather than 12MB for the full image (assuming a bitmap configuration of ARGB_8888).

My question is how you can calculate the image file size (or maybe I must say memory usage) of the image using the height and width like in the answer above. Also, what is this ARGB_8888 value or how to get it?

Upvotes: 1

Views: 1827

Answers (1)

Kobus Pitzer
Kobus Pitzer

Reputation: 574

ARGB_8888 is a way of storing information about the pixels.

Referring to the docs ARGB_8888 stores each pixel on 4 bytes.

To calculate the total possible size of the image, say the 512x384 example you were using we get the following.

512 x 384 = 196608 pixels.

And we know each pixel is stored on 4 bytes. Thus the total size in bytes will be 196608 x 4 = 786432 bytes.

From here we go and divide by 1024 , see here, for every step up the kB, MB, GB, TB ladder we want to go. So to get the MB size for the image we have 786432/(1024x1024) = 0.75.

Hope this answers your question

Upvotes: 5

Related Questions