Reputation: 11
I have looked for GetDIBits all over and only seem to find discussion in every other application other than Excel 2016.
I keep getting back 0 for all of the pixel values. I don't know if using Image1.Picture.Handle is the proper statement for the hdc, and I don't know if Image1.Picture is the proper statement for the hbitmap.
I can't even get a result to show up in an image box using the SetDIBits function.
Most of the content on the web uses PictureBox, and Autodraw, and stuff that doesn't seem to be in Excel.
Can anyone please help me solve this problem. It would be greatly appreciated. I would post all the Declarations but I didn't want to be booted of the site my question was too long. Thanks in advance.
Private Sub CommandButton2_Click() 'Userform command button
Dim X As Long 'X coordinates for the pixels
Dim Y As Long 'Y coordinates for the pixels
Dim sw As BITMAP
Dim bmapinfo As BITMAPINFO 'Information about the bitmap
Dim xtPixels() As RGBPixel 'Array to place pixel data into
Dim oPic As IPictureDisp 'Declaration of picture used in this program
Set oPic = Image1.Picture 'making the picture an object
'All of the data below gives information about the picture
bmapinfo.bmiHeader.biSize = 40
bmapinfo.bmiHeader.biWidth = oPic.Width
bmapinfo.bmiHeader.biHeight = oPic.Height
bmapinfo.bmiHeader.biPlanes = 1
bmapinfo.bmiHeader.biBitCount = 24
'bmapinfo.bmiHeader.biCompression = BI_RGB
bmapinfo.bmiHeader.biXPelsPerMeter = ((((bmapinfo.bmiHeader.biWidth * bmapinfo.bmiHeader.biBitCount) + _
31) \ 32) * 4)
bmapinfo.bmiHeader.biYPelsPerMeter = bmapinfo.bmiHeader.biXPelsPerMeter - (((bmapinfo.bmiHeader.biWidth _
* bmapinfo.bmiHeader.biBitCount) + 7) \ 8)
bmapinfo.bmiHeader.biSizeImage = bmapinfo.bmiHeader.biXPelsPerMeter * Abs(bmapinfo.bmiHeader.biHeight)
' GetObjectAPI voPicture.Handle, LenB(tBmp), tBmp
' nBitCount = tBmp.bmWidth * tBmp.bmBitsPixel * tBmp.bmHeight \ 4
ReDim xtPixels(1 To bmapinfo.bmiHeader.biWidth, 1 To bmapinfo.bmiHeader.biHeight)
'All of the data above gives information about the picture
GetDIBits Image1.Picture.Handle, sw.bmBitsPixel, _
0, bmapinfo.bmiHeader.biHeight, xtPixels(1, 1), bmapinfo, _
DIB_RGB_COLORS
For Y = 1 To UBound(xtPixels, 1) - 1
For X = 1 To UBound(xtPixels, 2) - 1
'With xtPixels(Y, X)
xtPixels(Y, X).Blue = xtPixels(Y, X).Blue
xtPixels(Y, X).Green = xtPixels(Y, X).Green
xtPixels(Y, X).Red = xtPixels(Y, X).Red
Next X, Y
SetDIBits oPic.Handle, oPic.Handle, _
0, bmapinfo.bmiHeader.biHeight, xtPixels(1, 1), _
bmapinfo, DIB_RGB_COLORS
'Set Image2.Picture = oPic.Render
End Sub
Upvotes: 1
Views: 617