long: Private Type BITMAP '14 bytes bmType As Long bmWidth As Long bmHeight As Long bmWidthBytes As Long bmPlanes As Integer bmBitsPixel As Integer bmBits As Long End Type
一个简单的例子: Option Explicit Private Type BITMAPFILEHEADER bfType(0 To 1) As Byte bfSize As Long bfReserved1 As Integer bfReserved2 As Integer bfOffBits 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 BmpFileInfo bmpwidth As Long bmpheight As Long bmpbitcount As Integer End TypePrivate Function GetBmpFileInfo(ByVal filename As String) As BmpFileInfo On Error GoTo MYERR Dim BMFH As BITMAPFILEHEADER Dim BMIH As BITMAPINFOHEADER Open filename For Binary As #1 Get #1, , BMFH Get #1, , BMIH Close #1 GetBmpFileInfo.bmpbitcount = BMIH.biBitCount GetBmpFileInfo.bmpheight = BMIH.biHeight GetBmpFileInfo.bmpwidth = BMIH.biWidth Exit Function MYERR: GetBmpFileInfo.bmpbitcount = 0 GetBmpFileInfo.bmpheight = 0 GetBmpFileInfo.bmpwidth = 0 MsgBox "发生错误" End FunctionPrivate Sub Command1_Click() Dim filename As String filename = "g:\mc\mc\12345m.bmp" Dim myfileinfo As BmpFileInfo myfileinfo = GetBmpFileInfo(filename) MsgBox filename + "文件信息:" + "宽度:" + CStr(myfileinfo.bmpwidth) _ + ",高度:" + CStr(myfileinfo.bmpheight) + _ ",颜色:" + CStr(myfileinfo.bmpbitcount) + "位" End Sub
Private Type BITMAP '14 bytes
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Option Explicit
Private Type BITMAPFILEHEADER
bfType(0 To 1) As Byte
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits 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 BmpFileInfo
bmpwidth As Long
bmpheight As Long
bmpbitcount As Integer
End TypePrivate Function GetBmpFileInfo(ByVal filename As String) As BmpFileInfo
On Error GoTo MYERR
Dim BMFH As BITMAPFILEHEADER
Dim BMIH As BITMAPINFOHEADER
Open filename For Binary As #1
Get #1, , BMFH
Get #1, , BMIH
Close #1
GetBmpFileInfo.bmpbitcount = BMIH.biBitCount
GetBmpFileInfo.bmpheight = BMIH.biHeight
GetBmpFileInfo.bmpwidth = BMIH.biWidth
Exit Function
MYERR:
GetBmpFileInfo.bmpbitcount = 0
GetBmpFileInfo.bmpheight = 0
GetBmpFileInfo.bmpwidth = 0
MsgBox "发生错误"
End FunctionPrivate Sub Command1_Click()
Dim filename As String
filename = "g:\mc\mc\12345m.bmp"
Dim myfileinfo As BmpFileInfo
myfileinfo = GetBmpFileInfo(filename)
MsgBox filename + "文件信息:" + "宽度:" + CStr(myfileinfo.bmpwidth) _
+ ",高度:" + CStr(myfileinfo.bmpheight) + _
",颜色:" + CStr(myfileinfo.bmpbitcount) + "位"
End Sub