gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:08:36 24 4
gpt4 key购买 nike

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

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

是否有任何其他方法可以产生第二种方法的结果但速度相当快?

最佳答案

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

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

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

关于C# WPF 需要快速缩小包含文本的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42182831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com