本文介绍了如何在WPF中的画布上画一条1像素厚的线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Line类在WPF中的画布上绘制,即使我设置了StrokeThickness = 1,该行也显示了2像素宽-几乎好像最小厚度是2像素.如何绘制一条真正的1像素粗的线?

I'm using the Line class to draw on a canvas in WPF and even though I set StrokeThickness = 1, the line shows up 2 pixels wide - it's almost as if the minimum thickness is two. How do I draw a line that is truly 1 pixel thick?

Line myLine = new Line();

myLine.Stroke = System.Windows.Media.Brushes.Black;

myLine.X1 = 100;
myLine.X2 = 140;  // 150 too far
myLine.Y1 = 200;
myLine.Y2 = 200;

myLine.StrokeThickness = 1;

graphSurface.Children.Add(myLine);

推荐答案

两件事:

myLine.SnapsToDevicePixels = true;
myLine.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);

这篇关于如何在WPF中的画布上画一条1像素厚的线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:03