【问题标题】:C# WPF Need quickly shrink images that contain textC# WPF 需要快速缩小包含文本的图像
【发布时间】:2017-02-12 00:18:38
【问题描述】:

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

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 Bicubic Sharper 一样好。不幸的是,它也很慢。对于我需要的东西来说太慢了。

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

【问题讨论】:

  • 你可以看到这个blog,它比较了几个图像处理库的性能和调整大小的图像质量。但结果并不令人惊讶——它们要么速度快,要么产生高质量的图像,但不能同时两者兼而有之。

标签: c# wpf winforms


【解决方案1】:

如果没有图片示例,很难给出可靠的建议。

例如,您的图像中已有多少对比度?您通过什么因素减少它们?

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

【讨论】:

    猜你喜欢
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多