问题
I have images like 5000*4000 pixels that I render every frame on form.
Such image loaded like Bitmap bmp = Image.FromFile("test.png");
uses around 100 mb RAM, while file size is 40 - 50 mb! That way my prog already uses ~500 bm RAM.
How to store that images more RAM efficient, but be able to cut parts from it fast enough? I have one huge image and cut parts from it to render according to view position. I call render method at 50 FPS and can't afford loading images from file every frame, since it too slow.
Is there any other way to store image in memory?
回答1:
You are stuck with having to have the uncompressed image loaded into memory if you wish to display it and manipulate it. There is no way round this.
The only sure way to reduce this is to reduce the resolution of the image being displayed. You could store the compressed image in memory and uncompress it from memory rather than from disk each time you need to change it.
Having said that 500MB of RAM is not that much these days where computers have several GB of RAM available.
来源:https://stackoverflow.com/questions/34656453/how-to-store-image-in-memory-more-compact-than-usual-bitmap-instance-and-access