2
我需要缩小包含文本的多个图像。由于文本需要缩小,以保留文本的锐利边缘而不平滑。我的第一次尝试如下:C#WPF需要快速缩小包含文本的图像
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一样好。不幸的是它也很慢。我需要的方式太慢了。
是否有任何其他方式可以产生第二种方法的结果,但速度相当快?
你可以看到这个[博客](https://blogs.msdn.microsoft.com/dotnet/2017/01/19/net-core-image-processing/),它比较了几个图像处理库性能和调整后的图像质量。但结果并不令人惊讶 - 它们要么速度很快,要么产生高质量的图像,但一次不能同时出现。 –