I'm trying to load a picture into excel and extract its pixels' RGB value into a 2D array.
However, When I try to use the GetPixel function, it always returns -1. I made sure it has loaded the picture onto a userform, but still returns -1.
Here's my code:
Private Declare PtrSafe Function GetPixel Lib "gdi32" (ByVal hDC As LongPtr, ByVal x As Long, ByVal Y As Long) As Long
Dim color As Long
UserForm1.Image1.Picture = LoadPicture("D:\Dropbox\Dropbox\1.bmp")
Debug.Print (UserForm1.Image1.Picture)
Debug.Print (GetPixel(UserForm1.Image1.Picture.Handle, 100, 100))
The getPixel
function isn't compatible with loadPicture
.
My solution was to load the picture onto a visible userform, then extract the pixels of the userform.