将 Tif 转换为 Jpg 需要很长时间
本文关键字:长时间 Jpg Tif 转换 | 更新日期: 2023-09-27 18:34:27
我正在尝试将许多(1000+)图像从tiff转换为jpg,但是在大约250-300张图像之后,任何进一步的图像大约需要5-10秒,即使前250张图像需要20秒。
这是我使用的代码:
foreach (string filePath in Directory.GetFiles(tifPath, "*.tif", SearchOption.AllDirectories))
{
System.Drawing.Image.FromFile(filePath).Save(jpgPath + "''" + Path.GetFileNameWithoutExtension(filePath) + ".jpg", ImageFormat.Jpeg);
}
我的方法有问题吗?提前谢谢。
图像需要被释放,否则它会保留在内存中:
foreach (string filePath in Directory.GetFiles(tifPath, "*.tif", SearchOption.AllDirectories))
{
using (var image = System.Drawing.Image.FromFile(filePath))
{
image.Save(jpgPath + "''" + Path.GetFileNameWithoutExtension(filePath) + ".jpg", ImageFormat.Jpeg);
}
}
有关使用语句的详细信息,请参阅此站点:
http://www.dotnetperls.com/using