从高度和宽度值获取图像文件大小

Get image file size from height and width values

根据这个答案here,可以读取图像 heightwidth 而无需将整个图像加载到内存中。

答案后面有一句话说

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).

我的问题是如何使用 heightwidth 就像上面的答案一样。另外,这个 ARGB_8888 值是多少或如何获得它?

ARGB_8888 is a way of storing information about the pixels.

参考docs ARGB_8888每个像素存储在4个字节上。

要计算图像的总可能大小,比如您使用的 512x384 示例,我们得到以下结果。

512 x 384 = 196608 像素。

而且我们知道每个像素都存储在 4 个字节上。因此,以字节为单位的总大小将为 196608 x 4 = 786432 字节。

我们从这里开始除以 1024,参见 here,对于我们想要达到的 kB、MB、GB、TB 阶梯的每一步。因此,为了获得图像的 MB 大小,我们有 786432/(1024x1024) = 0.75.

希望这能回答您的问题