如何根据C#中给出的输入坐标绘制多边形。根据输入坐标绘制多边形
回答
,因为根据这些坐标,你申请某种形式扩展到图像的你没有表现出任何代码。
使用PictureBox的Paint事件,这里是一个在屏幕上使用这些坐标的例子。它填补了多边形,然后绘制边框,然后它遍历所有的点来绘制红色圆圈:
void pictureBox1_Paint(object sender, PaintEventArgs e) {
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.Clear(Color.White);
// draw the shading background:
List<Point> shadePoints = new List<Point>();
shadePoints.Add(new Point(0, pictureBox1.ClientSize.Height));
shadePoints.Add(new Point(pictureBox1.ClientSize.Width, 0));
shadePoints.Add(new Point(pictureBox1.ClientSize.Width,
pictureBox1.ClientSize.Height));
e.Graphics.FillPolygon(Brushes.LightGray, shadePoints.ToArray());
// scale the drawing larger:
using (Matrix m = new Matrix()) {
m.Scale(4, 4);
e.Graphics.Transform = m;
List<Point> polyPoints = new List<Point>();
polyPoints.Add(new Point(10, 10));
polyPoints.Add(new Point(12, 35));
polyPoints.Add(new Point(22, 35));
polyPoints.Add(new Point(24, 22));
// use a semi-transparent background brush:
using (SolidBrush br = new SolidBrush(Color.FromArgb(100, Color.Yellow))) {
e.Graphics.FillPolygon(br, polyPoints.ToArray());
}
e.Graphics.DrawPolygon(Pens.DarkBlue, polyPoints.ToArray());
foreach (Point p in polyPoints) {
e.Graphics.FillEllipse(Brushes.Red,
new Rectangle(p.X - 2, p.Y - 2, 4, 4));
}
}
}
谢谢你是如此伟大的人:) – Mehmet
您可以使用Graphics.DrawPolygon。您可以将坐标存储在Point数组中,然后将其传递给DrawPolygon方法。你可能想看看:
Drawing with Graphics in WinForms using C#
private System.Drawing.Graphics g;
System.Drawing.Point[] p = new System.Drawing.Point[6];
p[0].X = 0;
p[0].Y = 0;
p[1].X = 53;
p[1].Y = 111;
p[2].X = 114;
p[2].Y = 86;
p[3].X = 34;
p[3].Y = 34;
p[4].X = 165;
p[4].Y = 7;
g = PictureBox1.CreateGraphics();
g.DrawPolygon(pen1, p);
在WinForms中,控件坐标从左上角开始,因此您需要将它们转换为左下角。 – JoanComasFdz
感谢您的回答,但我想看到我的多边形的角点不同的形状或颜色..而这个代码是没有用的。我有角点,我试图绘制像角点不同的多边形。我希望我能告诉我的问题..([链接](http://stackoverflow.com/questions/12081978/how-can-i-draw-in-picturebox-a-polygon-which-is-marked-on-边缘)这是我的秘密问题..) – Mehmet
@Mehmet,因为你必须为数组中的每个点绘制一个圆。你可以使用'DrawEllipse'方法 – Habib
- 1. 绘制多边形(Google地图)并在MySQL上插入坐标
- 2. 绘制组件不根据预期的坐标打印多边形
- 3. 排序多边形坐标绘图
- 4. 多边形坐标
- 5. 根据中心和边长计算正多边形的坐标
- 6. 绘制多边形的OpenLayers与WGS84坐标
- 7. 怎么看坐标从绘制多边形
- 8. 如何在地图上绘制填充多边形的坐标
- 9. 如何在Nutiteq上的交点坐标上绘制多边形?
- 10. 如何从给定坐标绘制多边形
- 11. 绘制多边形
- 12. 绘制多边形
- 13. 绘制多边形
- 14. 根据矩阵坐标绘制直线
- 15. 从坐标绘制矩形
- 16. 坐标点为多边形
- 17. Java输入坐标和绘制线
- 18. 绘制多边形,当鼠标点击
- 19. 如何根据简单的多边形绘制图像?
- 20. SVG坐标数组多边形形状
- 21. glDrawElements绘制多边形
- 22. 绘制多边形PyQt的
- 23. d3 Javascript - 绘制多边形
- 24. 如何根据GeoJSON返回的坐标创建多边形形状
- 25. 从用户输入的顶点绘制多边形google maps api
- 26. 绘制在x,y坐标的左边
- 27. 从mysql数据库中选择一行,根据lat,多边形的长坐标
- 28. 根据输入时间绘制圆弧
- 29. 闪亮:根据输入从源文件绘制图形
- 30. 如何将kml多边形几何数据转换为Google多边形坐标
什么应用程序的类型? winform wpf – Habib
@Habib,看着他的截图,那是winforms – Terry
[你试过什么](http://whathaveyoutried.com)?你卡在哪里? – Oded