如何在 visual basic 中存储和使用大量的 X 和 Y 坐标
How to store and use a large set of X and Y coordinates In visual basic
我分析了一幅图像,它收集了黑色像素的所有 XY 坐标。它有 6628 行长。格式为:
示例:
20, 552
26, 552
32, 552
我正在制作一个迷宫游戏,所有这些坐标值都是黑墙的周长。我怎样才能批量导入这些坐标以便我可以使用它们?
.NET 有一个名为 "point" 的内置结构。如果您正在收集积分,您将获得 collection 积分。
在分析图像的代码中,您可以随时存储它们:
示例:
Dim points As New List(Of Point)
points.Add(New Point(X, Y))
COLLECTIONS:
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/concepts/collections
要点:
https://docs.microsoft.com/en-us/dotnet/api/system.drawing.point.-ctor
您需要做的是读取文件并将文本解析为点。
要逐行读取文件,您可以使用 File.ReadLines 方法。
当你有一条线时,你可以split it on the delimiter character and if the correct number of items were found then try parsing the individual parts as integers. If that worked, you can add the data to a List(Of Point):
Function GetData(filename As String) As List(Of Point)
Dim pts As New List(Of Point)
Dim x As Integer
Dim y As Integer
For Each a In File.ReadLines(filename)
Dim parts = a.Split({","c}).Select(Function(p) p.Trim()).ToList()
If parts.Count = 2 Then
If Integer.TryParse(parts(0), x) AndAlso Integer.TryParse(parts(1), y) Then
pts.Add(New Point(x, y))
End If
End If
Next
Return pts
End Function
我分析了一幅图像,它收集了黑色像素的所有 XY 坐标。它有 6628 行长。格式为: 示例:
20, 552
26, 552
32, 552
我正在制作一个迷宫游戏,所有这些坐标值都是黑墙的周长。我怎样才能批量导入这些坐标以便我可以使用它们?
.NET 有一个名为 "point" 的内置结构。如果您正在收集积分,您将获得 collection 积分。
在分析图像的代码中,您可以随时存储它们:
示例:
Dim points As New List(Of Point)
points.Add(New Point(X, Y))
COLLECTIONS:
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/concepts/collections
要点:
https://docs.microsoft.com/en-us/dotnet/api/system.drawing.point.-ctor
您需要做的是读取文件并将文本解析为点。
要逐行读取文件,您可以使用 File.ReadLines 方法。
当你有一条线时,你可以split it on the delimiter character and if the correct number of items were found then try parsing the individual parts as integers. If that worked, you can add the data to a List(Of Point):
Function GetData(filename As String) As List(Of Point)
Dim pts As New List(Of Point)
Dim x As Integer
Dim y As Integer
For Each a In File.ReadLines(filename)
Dim parts = a.Split({","c}).Select(Function(p) p.Trim()).ToList()
If parts.Count = 2 Then
If Integer.TryParse(parts(0), x) AndAlso Integer.TryParse(parts(1), y) Then
pts.Add(New Point(x, y))
End If
End If
Next
Return pts
End Function