从左到右编号坐标和拉绳

Numbering coordinates and drawstring from left to right

我正在尝试使用对象的矩形 COG 对 blob 进行编号。但是矩形在椭圆路径上,因此我没有按正确的顺序得到它。

Font annotationFont = new Font("Verdana", 12, FontStyle.Bold);
Pen annotationPen = new Pen(Color.FromName("White"), 2.5f);

Graphics g = imageBoxMain.CreateGraphics();
for (int i = 0; i < totalrectcount; i++)
{
    Rectangle rect = new Rectangle(arrayX[i] /* blobid[i].name.Length * 6)*/, imageBoxMain.Image.Height - arrayminY[i]- 6, 100, 20);

    g.DrawString(Convert.ToString(i + 1), annotationFont, annotationPen.Brush, new System.Drawing.Point(rect.X, rect.Y));
}

这是我得到的:

我希望矩形从左到右标记。

所以你有两个数组,一个用于 X,一个用于 Y?

//far left is number 1, far right is 2, middle is 3
var arrayX = new[] { 100, 300, 200 };
var arrayY = new[] { 100, 95, 130 };

那会很痛苦;先将它们转换为Point的单个数组,然后对它们进行排序,然后绘制它们:

var points = new Point[arrayX.Length];
for(int x = 0; x<points.Length; x++){
  points[x] = new Point(arrayX[x], arrayY[x]);
}

foreach(Point r in points.OrderBy(p=>p.X)){
  Rectangle rect = new Rectangle(r.X /* blobid[i].name.Length * 6)*/, imageBoxMain.Image.Height - r.Y - 6, 100, 20);
  g.DrawString(Convert.ToString(i + 1), annotationFont, annotationPen.Brush, new System.Drawing.Point(rect.X, rect.Y));
}