2017-02-12 42 views
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一样好。不幸的是它也很慢。我需要的方式太慢了。

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

+0

你可以看到这个[博客](https://blogs.msdn.microsoft.com/dotnet/2017/01/19/net-core-image-processing/),它比较了几个图像处理库性能和调整后的图像质量。但结果并不令人惊讶 - 它们要么速度很快,要么产生高质量的图像,但一次不能同时出现。 –

回答

0

没有您的图像的例子很难给出可靠的建议。

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

您可以尝试最近的邻域缩放比例,它可以非常快,然后尝试使用高斯滤波器或类似方法将输出稍微模糊。如果这太混乱了,你也可以尝试使用柔和模糊进行线性缩放。