Loading a picture file Image.FromFile VS FileStream

后端 未结 4 1875
清酒与你
清酒与你 2020-12-19 08:59

I must admit that I never understood what are the streams are all about- I always thought it\'s an internet thing. But now I run into a code that used a stream to load a fil

4条回答
  •  长情又很酷
    2020-12-19 09:34

    Well, a file is often treated as a stream as well. That's why the primary class to open files is called FileStream. But there's a specific operating system feature that can make dealing with image files a lot more efficient. It is called 'memory mapped files', a feature that maps the content of a file directly to memory. There's some smoke and mirrors involved, but it essentially makes the file directly available without having to read it. The memory you need to store the file data doesn't take space in the paging file.

    Very efficient, you'll get it for free when you use FromFile() or the Bitmap(string) constructor for an image in the .bmp format. Loading an image from a stream tends to require twice the amount of memory, always a problem with big images.

提交回复
热议问题