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);
    }
}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM