C# 缩放图像并将其保存到文件夹,而不是在运行时缩放和使用

C# 缩放图像并将其保存到文件夹,而不是在运行时缩放和使用,c#,C#,首先,很抱歉这个标题,但我不知道如何更好地解释它。 这是我的问题。我正在缩放图像,检查重复的图像并对其进行水印处理。有趣的是,当我将它们保存到“/temp/”文件夹时,整个过程比在内存中加载它们时缩放和使用它们要快 这是我用于缩放的代码: private static Bitmap ScaleImage(string pathToImage, int maxWidth, int maxHeight) { Bitmap image = new Bitmap(pathToImage);

首先,很抱歉这个标题,但我不知道如何更好地解释它。 这是我的问题。我正在缩放图像,检查重复的图像并对其进行水印处理。有趣的是,当我将它们保存到“/temp/”文件夹时,整个过程比在内存中加载它们时缩放和使用它们要快

这是我用于缩放的代码:

private static Bitmap ScaleImage(string pathToImage, int maxWidth, int maxHeight)
{
    Bitmap image = new Bitmap(pathToImage);
    var ratioX = (double)maxWidth / image.Width;
    var ratioY = (double)maxHeight / image.Height;
    var ratio = Math.Min(ratioX, ratioY);

    var newWidth = (int)(image.Width * ratio);
    var newHeight = (int)(image.Height * ratio);

    var newImage = new Bitmap(newWidth, newHeight);
    Graphics.FromImage(newImage).DrawImage(image, 0, 0, newWidth, newHeight);
    Bitmap bmp = new Bitmap(newImage);

    return bmp;
}
然后我将缩放图像分配给变量:

Image imageLeft = ScaleImage(tempImage1, 48, 48);
Image imageRight = ScaleImage(tempImage2, 48, 48);
。。。并对它们进行比较

所以,让我困扰的是,为什么这比将所有缩放的图像保存在文件夹中然后进行比较要慢