使用 ImageBrush 时是否可以在 WPF 中关闭抗锯齿功能?
给定以下代码:
var handleImage = new BitmapImage(new Uri($"pack://application:,,,/Resources/myimage.png"));
var imageBrush = new ImageBrush(handleImage);
imageBrush.AlignmentY = AlignmentY.Top;
imageBrush.AlignmentX = AlignmentX.Left;
imageBrush.Stretch = Stretch.Uniform;
imageBrush.Viewport = new Rect(0, 0, _handleImage.Width, _handleImage.Height);
imageBrush.ViewportUnits = BrushMappingMode.Absolute;
imageBrush.TileMode = TileMode.Tile;
drawingContext.DrawRectangle(imageBrush, null, new Rect(0, 0, width, height));
WPF 的默认抗锯齿使它看起来很糟糕。我在窗户上试过UseLayoutRounding=true
, SnapsToDevicePixels=true
, RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.HighQuality)
,
。RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.NearestNeighbor)
RenderOptions.SetEdgeMode(this, EdgeMode.Unspecified);
唯一改变任何视觉差异的是BitmapScalingMode.NearestNeighbor
它仍然看起来很奇怪并且平铺重叠自身。
编辑:下载完整的工作示例:WpfImageBrushExample.zip