我一直在寻找 GetDIBits,似乎只能在 Excel 2016 以外的所有其他应用程序中找到讨论。
对于所有像素值,我不断返回 0。我不知道使用 Image1.Picture.Handle 是否是 hdc 的正确语句,我不知道 Image1.Picture 是否是 hbitmap 的正确语句。
我什至无法使用 SetDIBits 函数将结果显示在图像框中。
Web 上的大部分内容都使用 PictureBox、Autodraw 以及 Excel 中似乎没有的东西。
谁能帮我解决这个问题。这将不胜感激。我会发布所有声明,但我不想被网站引导,我的问题太长了。提前致谢。
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