原文在这里: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);
    }
}

  

相关文章:

  • 2021-06-04
  • 2021-12-05
  • 2021-07-09
  • 2021-10-07
  • 2022-03-05
  • 2022-12-23
  • 2022-02-18
  • 2021-08-24
猜你喜欢
  • 2021-08-18
  • 2022-12-23
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
相关资源
相似解决方案