Why is a Bitmap in memory much larger than image file on disk?

时间:2018-04-20 00:35:00

标签: winforms bitmap

I have an image file that is 6 mb on disk.

When I load it using

Dim nBmp As Bitmap = Bitmap.FromFile(sPath)

... TaskManager shows an increase of used RAM of my app of around 200 mb.

I could confirm this because if I do this around 6 times, the RAM goes up to 1,2 GB, and further attempts to do that raise an out-of-memory error.

So it's actually true that so much is being used. I don't process this bitmap any further.

Why is the bitmap so much larger than the file on the disk?

1 个答案:

答案 0 :(得分:3)

您正在加载压缩图像。 PNG在你的情况下。 Bitmap.FromFile将对其进行解压缩,然后将其作为未压缩的Bitmap加载到内存中。这需要更多的空间。正如你在评论中所说:PNG为6MB,Bitmap为190MB。