據我所知,從C#中的圖片/圖像文件中讀取尺寸(寬度和高街技度)的最快方法是:
DateTime startDateTime = 很美DateTime.Now;string source男關Folder = @"C:\Temp";// Get all files f白工rom sourcefolder, including sub現雨folders.string[] sourceFiles議北 = Directory.GetF畫慢iles(sourceFolder, "*", SearchOption.水算AllDirectories);foreach (strin鐘林g file in sourceFiles){ using 美年(Stream stream = File.OpenRea體黑d(file)) { using (Image s湖地ourceImage = Image.FromS日討tream(stream, false, false)) 對現 { Console.遠影WriteLine(sourceImage.Wi家劇dth); Console.WriteLine(相輛sourceImage.Height); }又用 }}DateTime endDateTime = DateTim公事e.Now;Console.WriteLine(string.Fo哥黃rmat( "Total duration [{0}] second姐不s. Total image count [市機{1}].", (e街拿ndDateTime - startDa雪湖teTime).TotalSeconds, sou問低rceFiles.Length));
總持續時(shí)間[01855235]秒。總圖像計務校數[33]。
這(zhè)比原來的方法大約快250倍,原始方窗錯法:
DateTime startDateTime = DateTime.Now錯校;string sourceFolder = @"C:\Te制唱mp";// Get all files from so舊科urcefolder, including subfold店謝ers.string[] sourceFi又黑les = Directory.GetFiles(說子sourceFolder, "*",會志 SearchOption.AllDirectories);forea白都ch (string file in s舊討ourceFiles){ 林綠using (Image sourceImag知河e = Image.FromFile(file)) 森票 { Console.WriteLi請看ne(sourceImage.Width); 計妹 Console.Write站上Line(sourceImage.Height); }照生}DateTime endDateTime = Dat關從eTime.Now;Console.Write服下Line(string.Format( 章吃 "Total duration [{0}少森] seconds. Total image count [{人雜1}].", (en我飛dDateTime - startDateTime)科黃.TotalSeconds, s吃道ourceFiles.Length));
總持續時(shí)間[474575263]秒。總圖像計數[作秒33]。
網站無須三方授權 · 安全穩定、維護方便