如何在DrawingImage/DrawingContext中绘制没有模糊/模糊的线条?
问题描述:
查看图片。我想中间线是一个脆皮的1像素线。 您可以将示例标记复制并粘贴到kaxaml。如何在DrawingImage/DrawingContext中绘制没有模糊/模糊的线条?
alt text http://img832.imageshack.us/img832/1704/lines.png
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Image SnapsToDevicePixels="True" Stretch="None">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup>
<GeometryDrawing>
<GeometryDrawing.Pen>
<Pen Brush="Red" Thickness="1"/>
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<LineGeometry StartPoint="0,0" EndPoint="50,0"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing>
<GeometryDrawing.Pen>
<Pen Brush="Black" Thickness="1"/>
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<LineGeometry StartPoint="0,5.860" EndPoint="50,5.860"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing>
<GeometryDrawing.Pen>
<Pen Brush="Black" Thickness="1"/>
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<LineGeometry StartPoint="0,12" EndPoint="50,12"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
</Page>
答
更改中间线:
<LineGeometry StartPoint="0,6" EndPoint="50,6"/>
您可以通过将线整体编号单元上获得的像素边界上一个清晰的线。
答
我找到了解决方案: http://msdn.microsoft.com/en-us/library/system.windows.media.renderoptions.setedgemode.aspx
<Image Stretch="None" RenderOptions.EdgeMode="Aliased">
RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
+0
完美地工作并证明了我使用带有DrawingImage的图像,因为它的源代码与我通常用于XAML图标的DrawingBrush技术。 – jpierson 2012-12-27 06:38:11
答
我看到了类似的问题与边境控制,虽然@phi您的解决方案在大多数情况下工作,我也不得不添加以下让它完全工作:
SnapsToDevicePixels="True"
我正在寻找一个通用的解决方案,像一个标志。我在CoreGraphics中遇到了类似的问题,解决方案是将transform转换为我的上下文0.5,0.5 – phi 2010-07-20 01:07:30