據(jù)我所知,從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));總持續(xù)時(shí)間[01855235]秒。總圖像計(jì)數(shù)[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));總持續(xù)時(shí)間[474575263]秒。總圖像計(jì)數(shù)[33]。
網(wǎng)站無須三方授權(quán) · 安全穩(wěn)定、維護(hù)方便