我有一个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;
}
}
其输出如下:
(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)
现在我的问题是如何将点的位置分配给与json中的波纹管图像匹配的标签正如您在图像中看到的,Row1在位置(114,33)处有一个点]
所以我如何将标签分配给每个点位置,以得到类似{“ Row1”:“(114,33)”}
请不要每个标签文本都必须硬编码在其中>>
我有一个C#程序来处理图像并返回图像上点的位置,如下所示。public class Program {public static void Main(){var ...
rowHeight