C# 快速获得 图像大小

原文在这里:https://www.roelvanlisdonk.nl/2012/02/28/fastest-way-to-read-dimensions-from-a-picture-image-file-in-c/

对比了 Image.FromFile(file) 的方法,用流的方法,快了250倍。

简单说来,就是用 Stream,这样不用把整个文件 Load 到 Image 里,自带的 API 接口里,估计会从流头里就得到 文件的大小了。

using (Stream stream = File.OpenRead(file))
{
    using (Image sourceImage = Image.FromStream(stream, false, false))
    {
        Console.WriteLine(sourceImage.Width);
        Console.WriteLine(sourceImage.Height);
    }
}

  

原文地址:https://www.cnblogs.com/pencilstart/p/14052785.html