![](/img/trans.png)
[英]Properly getting X and Y coordinates from a text file and plot the curve
[英]Extracting points coordinates(x,y) from a curve c#
我有一條曲線,我使用graphics.drawcurve(pen,points,tension)方法在C#中的圖片框上繪制
無論如何,我可以提取曲線覆蓋的所有點(x,y坐標)嗎? 並將它們保存到數組或列表中,否則任何事情都會很棒,因此我可以在其他事情中使用它們。
我的代碼:
void Curved()
{
Graphics gg = pictureBox1.CreateGraphics();
Pen pp = new Pen(Color.Green, 1);
int i,j;
Point[] pointss = new Point[counter];
for (i = 0; i < counter; i++)
{
pointss[i].X = Convert.ToInt32(arrayx[i]);
pointss[i].Y = Convert.ToInt32(arrayy[i]);
}
gg.DrawCurve(pp, pointss, 1.0F);
}
提前謝謝了。
如果您確實想要一個像素坐標列表,仍然可以讓GDI +承擔繁重的工作:
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace so_pointsfromcurve
{
class Program
{
static void Main(string[] args)
{
/* some test data */
var pointss = new Point[]
{
new Point(5,20),
new Point(17,63),
new Point(2,9)
};
/* instead of to the picture box, draw to a path */
using (var path = new GraphicsPath())
{
path.AddCurve(pointss, 1.0F);
/* use a unit matrix to get points per pixel */
using (var mx = new Matrix(1, 0, 0, 1, 0, 0))
{
path.Flatten(mx, 0.1f);
}
/* store points in a list */
var list_of_points = new List<PointF>(path.PathPoints);
/* show them */
int i = 0;
foreach(var point in list_of_points)
{
Debug.WriteLine($"Point #{ ++i }: X={ point.X }, Y={point.Y}");
}
}
}
}
}
此方法將樣條線繪制到路徑,然后使用將路徑展平到足夠密集的線段集的內置功能(大多數矢量繪圖程序也這樣做),然后從線網格中提取路徑點進入PointF
的列表。
在此過程中,會丟失GDI +設備渲染的偽像(平滑,抗鋸齒)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.