如何在Drawing Image / DrawingContext中绘制非模糊/模糊线?

时间:2010-07-20 00:52:09

标签: wpf

查看图片。我希望中间线是一条1像素的香脆线。 您可以将示例标记复制并粘贴到kaxaml

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>

3 个答案:

答案 0 :(得分:9)

我找到了解决方案: http://msdn.microsoft.com/en-us/library/system.windows.media.renderoptions.setedgemode.aspx

<Image Stretch="None" RenderOptions.EdgeMode="Aliased">
RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);

答案 1 :(得分:1)

将中间线更改为:

<LineGeometry StartPoint="0,6" EndPoint="50,6"/>

通过将线放在整个编号单元上,可以在像素边界上获得清晰的线条。

答案 2 :(得分:0)

我在Border控件中看到了类似的问题,虽然@phi你的解决方案在大多数情况下都有效但我还必须添加以下内容才能使其完全正常工作:

SnapsToDevicePixels="True"