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