Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#WPF需要快速收缩包含文本的图像_C#_Wpf_Winforms - Fatal编程技术网

C#WPF需要快速收缩包含文本的图像

C#WPF需要快速收缩包含文本的图像,c#,wpf,winforms,C#,Wpf,Winforms,我需要收缩包含文本的多个图像。由于文本的原因,它们需要收缩,以保持文本的锐利边缘,而不是平滑。我的第一次尝试是: RenderOptions.SetBitmapScalingMode(upgradeCard, BitmapScalingMode.HighQuality); upgradeCard.Height(resizedHeight); upgradeCard.Width(resizedWidth); 结果太模糊,文本很难阅读。然而,它真的很快。然后我试了一下: public static

我需要收缩包含文本的多个图像。由于文本的原因,它们需要收缩,以保持文本的锐利边缘,而不是平滑。我的第一次尝试是:

RenderOptions.SetBitmapScalingMode(upgradeCard, BitmapScalingMode.HighQuality);
upgradeCard.Height(resizedHeight);
upgradeCard.Width(resizedWidth);
结果太模糊,文本很难阅读。然而,它真的很快。然后我试了一下:

public static class ImageResizer
{
    public static Image Resize(Image image, Size size)
    {
        if (image == null || size.IsEmpty)
            return null;

        var resizedImage = new Bitmap(size.Width, size.Height, image.PixelFormat);
        resizedImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

        using (var graphics = Graphics.FromImage(resizedImage))
        {
            var location = new Point(0, 0);
            graphics.CompositingMode = CompositingMode.SourceCopy;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.SmoothingMode = SmoothingMode.None;
            graphics.DrawImage(image, new Rectangle(location, size),
                               new Rectangle(location, image.Size), GraphicsUnit.Pixel);
        }

        return resizedImage;
    }
}
这个效果非常好,几乎和Photoshop的双三次锐化器一样好。不幸的是,速度也很慢。对我来说太慢了


有没有其他方法可以产生第二种方法的结果,但速度相当快?

没有图像示例,很难给出可靠的建议

例如,您的图像中已经有多少对比度?你用什么因素来减少它们

您可以尝试最近邻缩放,这可能非常快,然后尝试用高斯滤波器或类似方法稍微模糊输出。如果锯齿太多,您也可以尝试使用软模糊进行线性缩放。

您可以看到这一点,它比较了几种图像处理库的性能和调整大小的图像质量。但结果并不令人惊讶——它们要么速度快,要么生成高质量的图像,但不是同时生成两者。