Loading a picture file Image.FromFile VS FileStream

后端 未结 4 1874
清酒与你
清酒与你 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:45

    As an a addition to Jon´s answer:

    As far as I see, the two methods don't do the same thing either. The first is given you the first image in "C:\" where the second just give you a image from a path. So the added complexity in the first is not just because it is using streams.

    This would be equivalent:

    using (var fs = File.OpenRead(path))
    using (var img = Image.FromStream(fs))
    {
        //...
    }
    

    and in that case, it is certainly better to just do it with Image.FromFile as Jon explained.

提交回复
热议问题