C# 如何将图像上点的位置指定给其关联的文本标签

C# 如何将图像上点的位置指定给其关联的文本标签,c#,json,image-processing,bitmap,C#,Json,Image Processing,Bitmap,我有一个C#程序,它处理图像并返回图像上点的位置,如下所示 public class Program { public static void Main() { var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("ImageDotsToData.dots.png"); byte[] buffer = new byte[resource.Leng

我有一个C#程序,它处理图像并返回图像上点的位置,如下所示

    public class Program
{
    public static void Main()
    {
        var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream("ImageDotsToData.dots.png");

        byte[] buffer = new byte[resource.Length];
        resource.Read(buffer, 0, buffer.Length);

        var positions = GetDotsPositions(buffer);

        foreach (var position in positions)
        {
            Console.WriteLine(position);
        }

        Console.ReadLine();
    }

    public static List<Tuple<int, int>> GetDotsPositions(byte[] imgData)
    {
        int HEIGHT = 400;
        int WIDTH = 600;

        List<Tuple<int, int>> positions = new List<Tuple<int, int>>();
        Bitmap bitmap;
        using (Stream bmpStream = new MemoryStream(imgData))
        {
            Image image = Image.FromStream(bmpStream);
            bitmap = new Bitmap(image);
        }

        List<int> knownBlankColors = new List<int>();
        knownBlankColors.Add(Color.White.ToArgb());

        for (int x = 0; x < HEIGHT; x++)
        {
            for (int y = 0; y < WIDTH; y++)
            {
                Color pixelColor = bitmap.GetPixel(x, y);

                var code = pixelColor.ToArgb();

                if (!knownBlankColors.Contains(code))
                    positions.Add(new Tuple<int, int>(x, y));
            }
        }

        return positions;
    }
}
等等 对于下图

现在我的问题是如何将点的位置分配给与json中的bellow图像匹配的标签 如图所示,第1行在位置(114,33)处有一个点

那么,我如何将标签分配给每个点位置,从而得到如下结果 {“第1行”:(114,33)}


请不要认为每个标签文本都必须硬编码,如果您的行宽度相等,则它是基本匹配

  • 将图像高度除以行数,并分配给变量
    rowhight
  • 然后
  • //如果y>0且y((i-1)*行高)和&y<(i*行高)){
    返回i;
    }
    

    然后,您可以使用I创建或打印新集合。

    如果行的宽度相等,则它是基本匹配

  • 将图像高度除以行数,并分配给变量
    rowhight
  • 然后
  • //如果y>0且y((i-1)*行高)和&y<(i*行高)){
    返回i;
    }
    
    然后,您可以使用I创建或打印新收藏

    (114, 33)
    (114, 34)
    (114, 35)
    (114, 36)
    (114, 37)
    (114, 38)
    (114, 39)
    (114, 40)
    (115, 33)
    (115, 34)
    (115, 35)
    (115, 36)
    (115, 37)
    (115, 38)
    (115, 39)
    (115, 40)
    (116, 33)
    (116, 34)
    
     // if y > 0 and y < rowHeight, then it belongs to Row 1
     if( y > ((i-1) * rowHeight) && y < (i * rowHeight)) { 
          return i;
     }