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/),它比較了幾個圖像處理庫性能和調整後的圖像質量。但結果並不令人驚訝 - 它們要麼速度很快,要麼產生高質量的圖像,但一次不能同時出現。 –