【发布时间】: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,它比较了几个图像处理库的性能和调整大小的图像质量。但结果并不令人惊讶——它们要么速度快,要么产生高质量的图像,但不能同时两者兼而有之。