如题

解决方案 »

  1.   

    那么,有变通的办法吗?比如我想手工的从一个BMP图形文件中读去信息,需要分析图片的长度,那是一个DWORD型的数据,用VB该用什么方法读取?
      

  2.   

    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
      

  3.   

    一个简单的例子:
    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
      

  4.   

    首先感谢高手的指教,但是您举的例子中提取的3个数据都是LONG或INTEGER型的,而非DWORD型。 我担心的是无符号数如果直接用LONG(当成有符号数)读取的话,会产生错误,譬如您的例子中的BITMAPINFOHEADER.biSize数据,本来无符号数是可以用Currency以保证不溢出,但是数值上的转换好象没有已知的函数可以完成,除非自己做……
      

  5.   

    不好意思,上面提到的BITMAPINFOHEADER.biSize应该是BITMAPINFOHEADER.biSizeImage
      

  6.   

    呵呵,放心用吧,不会出问题vb提供的函数CCur可以将数值转为Currency型