wpf线描显示模糊 [英] wpf Line stroke shown blurry

查看:218
本文介绍了wpf线描显示模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS 2013预览版中创建了一个示例代码,在画布上用白色的笔触颜色绘制了一条线,但是该行显示得很奇怪,就像更粗而不是白色(几乎是灰色)一样. 我在VS 2010中尝试过的同一示例,并且输出良好.

I made a sample code in VS 2013 preview, I made a line inside a canvas with stroke color of white, but the line is shown so strangely like more thick and not white (almost gray). same sample I tried it in VS 2010 and it output well.

谁能告诉我发生了什么事...?

Can anyone tell me what's going on...?

<Canvas Width="200" Height="200" Background="Black">
    <Line X1="30" Y1="60" X2="90" Y2="60" Stroke="White" StrokeThickness="1"/>
    <Line X1="60" Y1="30" X2="60" Y2="90" Stroke="White" StrokeThickness="1"/>
</Canvas>

//编辑 当我将线的粗细更改为2或更大时,它显示为完全白色,但粗细为2.

//EDIT when I change the line thickness to 2 or more then it shows perfectly white but with thickness of 2.

推荐答案

这是我们的老朋友Pixel Snapping.当线条落在像素边界上时,WPF将使用与ClearType相似的技术来绘制线条.这就是您所看到的. VS版本之间可能会发生变化的原因是,它们可以在其他位置启动画布.

This is our old friend Pixel Snapping. WPF will use a similar technology to ClearType to draw lines when they fall on a pixel boundary. This is what you're seeing. The reason why it may change between versions of VS is that they can start your canvas in a different location.

Dave Relyea有一个很棒的像素捕捉控件来帮助解决这些问题.

Dave Relyea has a cool Pixel Snapping Control to help with just these problems.

由于他的控件是为Silverlight进行的,因此出于WPF的目的,我将UserControl更改为Decorator.只需将所有引用从Content更改为Child.这样,您就不必担心别人会应用ControlTemplate.

Since his control was made for Silverlight, I'd change UserControl to Decorator for WPF purposes. Just change all references from Content to Child. That way you won't have to worry about a ControlTemplate being applied by somebody else.

这篇关于wpf线描显示模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆