I want to copy the image in a picturebox to a 1D array of integers where each elment would be a pixel colour.
I'm wondering whether it's best to use .Net methods which partly I have yet to learn or rather stick to the API functions I was using in VB6, such as in this example provided to me by a forum user:
At any rate, I've been using .Net only for a short time and I still get lost in the new graphics methods. I need something like,Code:Public Function RetDIBDataLong(PictureObject As Object, Optional Return2DArray As Boolean) As Long()
Dim BM As BITMAP, bmi As BITMAPINFO, lngImageData() As Long
'The PictureObject must be an object with both a HDC and Image property
'such as a PictureBox, UserControl or Form
Dim hDC As Long, bReleaseDC As Boolean, hHandle As Long
If TypeOf PictureObject Is StdPicture Then
hHandle = PictureObject.Handle
bReleaseDC = True
Else
hHandle = PictureObject.Picture
hDC = PictureObject.hDC
End If
If GetObjectA(hHandle, 24, BM) = 0& Then Exit Function
bmi.bmHeader.bmWidth = BM.bmWidth
bmi.bmHeader.bmHeight = BM.bmHeight
bmi.bmHeader.bmSize = 40
bmi.bmHeader.bmPlanes = 1
bmi.bmHeader.bmBitCount = 32
If bReleaseDC Then hDC = GetDC(GetDesktopWindow)
If Return2DArray Then
ReDim lngImageData(BM.bmWidth - 1, BM.bmHeight - 1)
GetDIBits hDC, hHandle, 0, BM.bmHeight, lngImageData(0, 0), bmi, 0
Else
ReDim lngImageData(BM.bmWidth * BM.bmHeight - 1)
GetDIBits hDC, hHandle, 0, BM.bmHeight, lngImageData(0), bmi, 0
End If
If bReleaseDC Then ReleaseDC GetDesktopWindow, hDC
RetDIBDataLong = lngImageData
End Function
Dim imgArray as Integer() = SomeFunction(PictureBox1.Image)

