搜索历史

清除历史

热门搜索

网络工作室网站建设seo优化小程序

零基础干货

零基础干货

SERVICE CENTER

C#读取图片/图像文件尺寸的最快方法

网站建设 2022/9/16 7:17:34    admin    阅读 1422

据我所知,从C#中的图片/图像文件中读取尺寸(宽度和高度)的最快方法是:


DateTime startDateTime = DateTime.Now;string sourceFolder = @"C:\Temp";// Get all files from sourcefolder, including subfolders.string[] sourceFiles = Directory.GetFiles(sourceFolder, "*", SearchOption.AllDirectories);foreach (string file in sourceFiles){
    using (Stream stream = File.OpenRead(file))
    {
        using (Image sourceImage = Image.FromStream(stream, false, false))
        {
            Console.WriteLine(sourceImage.Width);
            Console.WriteLine(sourceImage.Height);
        }
    }}DateTime endDateTime = DateTime.Now;Console.WriteLine(string.Format(
    "Total duration [{0}] seconds. Total image count [{1}].", 
    (endDateTime - startDateTime).TotalSeconds, 
    sourceFiles.Length));


总持续时间[01855235]秒。总图像计数[33]。


这比原来的方法大约快250倍,原始方法:


DateTime startDateTime = DateTime.Now;string sourceFolder = @"C:\Temp";// Get all files from sourcefolder, including subfolders.string[] sourceFiles = Directory.GetFiles(sourceFolder, "*", SearchOption.AllDirectories);foreach (string file in sourceFiles){
    using (Image sourceImage = Image.FromFile(file))
    {
        Console.WriteLine(sourceImage.Width);
        Console.WriteLine(sourceImage.Height);
    }}DateTime endDateTime = DateTime.Now;Console.WriteLine(string.Format(
    "Total duration [{0}] seconds. Total image count [{1}].", 
    (endDateTime - startDateTime).TotalSeconds, 
    sourceFiles.Length));


总持续时间[474575263]秒。总图像计数[33]。


TAG标签:c#c#图片尺寸
链接地址:/html/tech/wzjs/1528.html
郑重声明:以上内容来源自玖捌网络工作室,转载请注明出处!

兼顾高品质与个性化的界面设计

网站无须三方授权 · 安全稳定、维护方便

玖捌网络工作室
18972931619
扫码获取最新报价
0.053717