|
回复 zhuyiwen 的帖子
- 下面的代码从位图句柄获取位图数据
- Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
- Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
- Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
- Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
- Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
- Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
- Private Type bitmap
- bmType As Long
- bmWidth As Long
- bmHeight As Long
- bmWidthBytes As Long
- bmPlanes As Integer
- bmBitsPixel As Integer
- bmBits As Long
- End Type
- Private Type BITMAPINFOHEADER
- biSize As Long
- biWidth As Long
- biHeight As Long
- biPlanes As Integer
- biBitCount As Integer
- biCompression As Long
- biSizeImage As Long
- biXPelsPerMeter As Long
- biYPelsPerMeter As Long
- biClrUsed As Long
- biClrImportant As Long
- End Type
- Private Type RGBQUAD
- rgbBlue As Byte
- rgbGreen As Byte
- rgbRed As Byte
- rgbReserved As Byte
- End Type
- Private Type BITMAPINFO
- bmiHeader As BITMAPINFOHEADER
- bmiColors As RGBQUAD
- End Type
- Private Const DIB_RGB_COLORS = 0
- Private Const BI_RGB = 0&
- Private Function GetPictureDataFromBitmap(hBitmap As Long, bPictureData() As Byte) As Boolean
- Dim bm As bitmap
- Dim bi24BitInfo As BITMAPINFO
- Dim hMemDc As Long
- Dim bBytes() As Byte
- GetObject hBitmap, Len(bm), bm
- With bi24BitInfo.bmiHeader
- .biWidth = bm.bmWidth
- .biHeight = bm.bmHeight
- .biBitCount = 24
- .biCompression = BI_RGB
- .biPlanes = 1
- .biSize = Len(bi24BitInfo.bmiHeader)
- End With
- ReDim bBytes(1 To ((bm.bmWidth * 3 + 3) \ 4) * 4 * bm.bmHeight) As Byte
- hMemDc = CreateCompatibleDC(0)
- GetDIBits hMemDc, hBitmap, 0, bm.bmHeight, bBytes(1), bi24BitInfo, DIB_RGB_COLORS
-
- ReDim bPictureData(bi24BitInfo.bmiHeader.biSizeImage + 40)
- CopyMemory bPictureData(40), bBytes(1), bi24BitInfo.bmiHeader.biSizeImage
- CopyMemory bPictureData(0), bi24BitInfo.bmiHeader, 40
- DeleteDC hMemDc
- DeleteObject hBitmap
- End Function
复制代码 6楼的代码可以获得StdPicture对象,此代码可将StdPicture对象转为access.image控件支持的位图数据,此代码结合6楼的代码如下使用即可:
Dim bPictureData() As Byte
GetPictureDataFromBitmap LoadPictureFromField(f).Handle, bPictureData()
Me.Image1.PictureData = bPictureData() |
|