I have VB 2008 code that searches through individual pixels of a section of a grayscale bitmap image. If the pixel values are less than 72, I want to store the coordinates of the pixel in a two dimensional array.
When I run my code I get the following error: “Value of type ‘integer’ cannot be converted to ‘two dimensional array of integer’.
My code is shown below. This code is in a loop that gets the indivdual pixel values. Any suggestions on what I’m doing wrong?
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
If you want to simply save the list of Pixel coordinates, you’d be much easier off with more advanced data types, like
Arrays are much work to care about. You have to initialize the Array before the loop with something like
And in the loop something like
The first dimension stays from 0 to 1 (to store two values) and cannot be changed. Read about
ReDim Preserveif you’re confused about this 😉