我正在使用WPF构建一个C#应用程序,我想要绘制形状。每个形状都属于一个类,该类包含一个多边形作为外形,以及1到3条折线使其看起来像真正的2D对象。这样,我可以在运行时更改整个形状的某些属性(颜色、可见性等)。需要注意的是,有些折线是根据所需的高度和宽度创建的循环。
但是现在我遇到了一些渲染PolyLines的问题。如果使用画图工具表示调试结束后提取的点,则点的位置(x,y)是正确的,但最终图片不够准确,我希望最终结果看起来像位图像素,没有阴影、模糊或边缘效果。
这是一个示例(Panel是给网格命名的)。
这张图片展示了上面绘制的锯齿形状,应该在下面看起来像这样。
但是现在我遇到了一些渲染PolyLines的问题。如果使用画图工具表示调试结束后提取的点,则点的位置(x,y)是正确的,但最终图片不够准确,我希望最终结果看起来像位图像素,没有阴影、模糊或边缘效果。
这是一个示例(Panel是给网格命名的)。
public partial class Window1 : Window {
private Polyline zigzag;
public Window1() {
InitializeComponent();
PointCollection points = new PointCollection();
ArrayList axisX = new ArrayList();
ArrayList axisY = new ArrayList();
zigzag = new Polyline();
zigzag.Stroke = Brushes.Black;
int count = 1;
Boolean increase = true;
//the number 60 in this loop is to represent the width of the main shape
for (int p = 3; p < 60 - 3; p++) {
if (count == 1) {
axisX.Add(p);
axisY.Add(5);
increase = true;
}
if (count == 4) {
axisX.Add(p);
axisY.Add(2);
increase = false;
}
if (increase) {
count++;
}
else {
count--;
}
}
for (int i = 0; i < axisX.Count; i++) {
//the number 10 is to represent the position where the Poliline is to be placed
int tmpx = 10 + (int)axisX[i];
int tmpy = 10 + (int)axisY[i];
points.Add(new Point(tmpx, tmpy));
}
this.zigzag.Points = points;
RenderOptions.SetEdgeMode(Panel , EdgeMode.Aliased);
Panel.Children.Add(zigzag);
}
}
这张图片展示了上面绘制的锯齿形状,应该在下面看起来像这样。