是否可以在 WPF Image 控件中更改图像插值的质量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14786986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to change the quality of the image interpolation in WPF Image control?
提问by Mixer
Image control - placed into Viewbox. For automatic scaling when the window size changes. Everything works perfect.
图像控件 - 放入 Viewbox。用于在窗口大小更改时自动缩放。一切都很完美。
Is it possible to change the type of interpolation in my case? For example select Bicubic or Bilinear. Or for automatic scaling of such a choice is not available?
在我的情况下,是否可以更改插值类型?例如选择双三次或双线性。或者对于这种选择的自动缩放是不可用的?
BitmapImage bmp=new BitmapImage(new Uri("c:/temp/1.jpg"));
ImageSource pic = bmp;
Viewbox vb = new Viewbox();
vb.Stretch = Stretch.UniformToFill;
vb.StretchDirection = StretchDirection.DownOnly;
Image img=new Image();
img.Source = pic;
vb.Child = img;
回答by Hyman
As far as I know you can't specify bicubic or bilinear interpolation for a bitmap in WPF, (the default is linear) but you can set RenderOptions.BitmapScalingModeoption to get better control of the display quality of the scaled bitmap. For example:
据我所知,您无法在 WPF 中为位图指定双三次或双线性插值(默认为线性),但您可以设置RenderOptions.BitmapScalingMode选项以更好地控制缩放位图的显示质量。例如:
RenderOptions.BitmapScalingMode="NearestNeighbor"or RenderOptions.BitmapScalingMode="HighQuality"
RenderOptions.BitmapScalingMode="NearestNeighbor"或者 RenderOptions.BitmapScalingMode="HighQuality"
There's more info on each of the scaling modes on MSDN http://msdn.microsoft.com/en-us/library/system.windows.media.bitmapscalingmode
MSDN http://msdn.microsoft.com/en-us/library/system.windows.media.bitmapscalingmode上有关于每种缩放模式的更多信息
If you still have issues with blurry graphics try setting UseLayoutRounding="True"in your root element. This will disable sub-pixel positioning of elements that can can cause jagged lines in WPF applications
如果您仍然遇到模糊图形的问题,请尝试UseLayoutRounding="True"在根元素中进行设置。这将禁用可能导致 WPF 应用程序中出现锯齿线的元素的亚像素定位

