1

我在 VB 2008 中工作。我使用 List(Of Point) 数据类型来存储位图中某些像素值的坐标:

'This code is in a loop
Dim bpCoordinates As New List(Of Point)
If pixelClr > 72 Then
bpCoordinates.Add(New Point(FrameNumber, y))
End If

我想使用 (y2 - y1)/(x2 - x1) 计算列表中存储点之间的斜率。我遇到的问题是访问列表中的点。我不知道如何做到这一点。

我在网上查看,找不到从列表中提取单个坐标点的任何方法。有什么建议么。谢谢。

4

1 回答 1

0

如果它们列在 List 中,您可以像在数组中一样直接访问元素 - 尽管这效率低下。

'Returns the nth list element
Dim p As Point = bpCoordinates(n)

将它存储在数组中会好得多,尤其是如果您的列表很长。

Dim pointArray As Point() = bpCoordinates.ToArray

之后只需正常遍历您的列表或数组即可。

Dim slope As Double

For index As Integer = 0 To pointArray.Length - 1
     slope = (pointArray(index + 1).Y - pointArray(index).Y) / (pointArray(index + 1).X - pointArray(index).X)
     'Do fun stuff with slope
Next
于 2013-02-20T21:54:12.327 回答