1

我有 VB 2008 代码,可以搜索灰度位图图像部分的单个像素。如果像素值小于 72,我想将像素的坐标存储在二维数组中。

当我运行我的代码时,出现以下错误:“'integer' 类型的值不能转换为'二维整数数组'。

我的代码如下所示。此代码位于获取单个像素值的循环中。关于我做错了什么有什么建议吗?

Dim bpCoordinates(,) As Integer
Dim yindex As Integer
Dim xindex As Integer
'If pixel value is < 72, store in array
'Framenumber and y are the integer values of the pixel coordinate
'xindex and yindex are the index values for the array that I want to store the coordinates in
If pixelValue < 72 Then                    
    bpCoordinates = (FrameNumber, y  xindex,yindex )
    yindex = yindex + 1
    xindex = xindex + 1
End If
4

1 回答 1

1

如果您只想保存像素坐标列表,使用更高级的数据类型会更容易,例如

   Dim pixelList As New List(Of Point)
   ...
   pixelList.Add(New Point(xValue, yValue))

数组是很多需要关心的工作。你必须在循环之前初始化数组,比如

ReDim bpCoordinates(1, 0)  

在循环中类似

    n = n + 1
    ReDim Preserve bpCoordinates(1, n)
    bpCoordinates(0, n) = Framenumber
    bpCoordinates(1, n) = y

第一个维度保持从 0 到 1(存储两个值)并且不能更改。ReDim Preserve如果您对此感到困惑,请阅读;-)

于 2013-01-27T21:07:44.017 回答