Dim BFH As BITMAPFILEHEADER
Dim BIH As BITMAPINFOHEADER
Dim BMPBits() As Byte
Dim FN As Long
Dim picTmp As Long, h As Long
Dim BI As BITMAPINFO
FN = FreeFile
Open sFileName For Binary As #FN
Get #FN, , BFH
Get #FN, , BI.bmiHeader
ReDim BMPBits(BI.bmiHeader.biWidth * BI.bmiHeader.biHeight)
Get #FN, , BI.bmiColors()
Seek #FN, 1078
Get #FN, , BMPBits()
Close #FN
Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Private Type BITMAPINFOHEADER '40 bytes
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 BITMAPINFO_1BPP
bmiHeader As BITMAPINFOHEADER
bmiColors(0 To 1) As RGBQUAD
End Type
Private Type BITMAPINFO_4BPP
bmiHeader As BITMAPINFOHEADER
bmiColors(0 To 15) As RGBQUAD
End Type
Private Type BITMAPINFO_8BPP
bmiHeader As BITMAPINFOHEADER
bmiColors(0 To 255) As RGBQUAD
End Type
Private Type BITMAPINFO_ABOVE8
bmiHeader As BITMAPINFOHEADER
End Type
Private Const DIB_PAL_COLORS = 1 ' color table in palette indices
Private Const DIB_PAL_INDICES = 2 ' No color table indices into surf palette
Private Const DIB_PAL_LOGINDICES = 4 ' No color table indices into DC palette
Private Const DIB_PAL_PHYSINDICES = 2 ' No color table indices into surf palette
Private Const DIB_RGB_COLORS = 0 ' color table in RGBs
Private Declare Function GetDIBits Lib "gdi32" (ByVal hdc As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As Any, ByVal wUsage As Long) As Long
Private Declare Function SetDIBits Lib "gdi32" (ByVal hdc 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 Sub Command1_Click()
On Error Resume Next
Dim tBI As BITMAPINFO_8BPP
Dim Bit() As Byte, lSize1 As Long
With tBI.bmiHeader
.biSize = Len(tBI.bmiHeader)
.biWidth = 图片宽
.biHeight = 图片高
.biPlanes = 1
.biBitCount = 8
.biCompression = BI_RGB
End With
'调色数据
For i = 0 To 255
tBI.bmiColors(i).rgbRed = r
tBI.bmiColors(i).rgbGreen = g
tBI.bmiColors(i).rgbBlue = b
Next