为 WPF 形状启用抗锯齿
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14227031/
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
Enable Anti-Aliasing for WPF shapes
提问by hypehuman
It seems that many people are trying to turn OFF anti-aliasingin WPF, but I seem to have the opposite problem. I am drawing shapes in WPF, and the edges are all aliased and ugly. The worst part is that when I use a ScaleTransform to zoom out such that a shape is less than one pixel tall/wide, it disappears entirely. How can I make them smooth and pretty?
似乎很多人都试图关闭anti-aliasingin WPF,但我似乎遇到了相反的问题。我在 中绘制形状WPF,边缘都是锯齿状和丑陋的。最糟糕的是,当我使用 ScaleTransform 缩小形状以使其高度/宽度小于一个像素时,它会完全消失。我怎样才能使它们光滑漂亮?
Currently, I am drawing Rectanglesand Ellipsesand placing them in grids and StackPanels.
目前,我画Rectangles,并Ellipses与将它们放置在电网和StackPanels。
After a lot of googling, I found out how to get my images to anti-aliasby using the following line in my window's constructor: RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.Fant);
经过大量的谷歌搜索,我发现了如何anti-alias通过在我的窗口的构造函数中使用以下行来获取我的图像:RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.Fant);
However, this only affects my Images and not my Shapes.
但是,这只会影响我的图像而不是我的形状。
回答by sa_ddam213
You can set the EdgeModethe same way you set BitmapScalingMode
你可以EdgeMode按照你设置的方式设置BitmapScalingMode
RenderOptions.SetEdgeMode(this, EdgeMode.Unspecified);
But Anti-Aliasingis set as default so you should not need to change it, but give it a go :)
但是Anti-Aliasing设置为默认值,因此您不需要更改它,但可以试一试:)
Also setting SnapsToDevicePixels = true;on your window may help with the shapes.
SnapsToDevicePixels = true;在您的窗口上设置也可能有助于形状。
回答by Torbj?rn Kalin
I have what I think is the same problem. Setting SnapsToDevicePixelsto false works for me:
我有我认为同样的问题。设置SnapsToDevicePixels为 false 对我有用:
<Ellipse SnapsToDevicePixels="False" />

