你需要知道文件头格式,只有这样操作才会方便。比如下列代码是读BMP文件头的。(获取BMP文件的宽与高及色彩),也许对你有帮助!Option Explicit
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 BITMAPFILEHEADER
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Public Type BITMAPINFO
Width As Long
Height As Long
Planes As Long
Colors As Long
End TypePublic Function GetBitmapInfo(psPath As String) As BITMAPINFO
Dim f As Integer
Dim tmp As String
Dim FileHeader As BITMAPFILEHEADER
Dim InfoHeader As BITMAPINFOHEADER
Dim i As BITMAPINFO
On Error Resume Next
f = FreeFile
Open psPath For Binary Access Read As #f
Get #f, , FileHeader
Get #f, , InfoHeader
Close #f
i.Width = InfoHeader.biWidth
i.Height = InfoHeader.biHeight
i.Planes = InfoHeader.biPlanes
i.Colors = CLng((InfoHeader.biBitCount & 2 ^ InfoHeader.biBitCount) / 1000)
GetBitmapInfo = i
End Function
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 BITMAPFILEHEADER
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Public Type BITMAPINFO
Width As Long
Height As Long
Planes As Long
Colors As Long
End TypePublic Function GetBitmapInfo(psPath As String) As BITMAPINFO
Dim f As Integer
Dim tmp As String
Dim FileHeader As BITMAPFILEHEADER
Dim InfoHeader As BITMAPINFOHEADER
Dim i As BITMAPINFO
On Error Resume Next
f = FreeFile
Open psPath For Binary Access Read As #f
Get #f, , FileHeader
Get #f, , InfoHeader
Close #f
i.Width = InfoHeader.biWidth
i.Height = InfoHeader.biHeight
i.Planes = InfoHeader.biPlanes
i.Colors = CLng((InfoHeader.biBitCount & 2 ^ InfoHeader.biBitCount) / 1000)
GetBitmapInfo = i
End Function
谢谢你,请发到[email protected]