各位VB高手,请问在VB中怎样生成一个BMP位图文件,要调用API中的函数吗?或是什么结构,请帮忙写一下源代码(只有生成两个正方形,大的里面画小的),非常感谢

解决方案 »

  1.   

    SAVEPICTURE PICTURE1.PICTURE,"C:\KK.BMP"SAVEPICTURE PICTURE1.IMAGE,"C:\KK.BMP"
      

  2.   

    使用picture对象的方法。如上。
      

  3.   

    谢谢上面的两位.要求的是先要将一些文件头,位图信息等添加到一个新文件中而生成一个BMP文件,不知要不要什么结构或API函数的
      

  4.   

    Public Type BITMAPFILEHEADER
        bfType(1 To 2) As Byte
        bfSize As Long
        bfReserved1 As Integer
        bfReserved2 As Integer
        bfOffBits As Long
    End TypePublic Type RGBQuad
        rgbBlue As Byte
        rgbGreen As Byte
        rgbRed As Byte
        rgbReserved As Byte
    End Type
    Public Declare Function GetDIBColorTable Lib "gdi32" (ByVal hDC As Long, ByVal un1 As Long, ByVal un2 As Long, pRGBQuad As RGBQuad) As LongPrivate Function ChkFileWrite(FileName As String) As Boolean
        Dim FileNum As Integer
        
        FileNum = FreeFile
        
        On Error Resume Next
        
        Open FileName For Output As #FileNum
        
        If Err.Number Then
            '
        Else
            Close #FileNum
            ChkFileWrite = True
        End If
        
        On Error GoTo 0
        
    End FunctionPublic Function SaveBMP(FileName As String) As Boolean
        Dim FileNum As Integer
        Dim TempBMFH As BITMAPFILEHEADER
        Dim TCB() As RGBQuad
        Dim TempBytes() As Byte
        
        If (ChkFileWrite(FileName) = False) Or (MyPtr = 0) Then Exit Function
        
        TempBMFH.bfType(1) = Asc("B")
        TempBMFH.bfType(2) = Asc("M")
        TempBMFH.bfOffBits = Len(TempBMFH) + Len(MyBMI.bmiHeader)
        If MyBMI.bmiHeader.biBitCount <= 8 Then
            TempBMFH.bfOffBits = TempBMFH.bfOffBits + 4 * 2 ^ MyBMI.bmiHeader.biBitCount
            
            ReDim TCB(1 To 2 ^ MyBMI.bmiHeader.biBitCount)
            GetDIBColorTable MyhDC, 0, 2 ^ MyBMI.bmiHeader.biBitCount, TCB(1)
            
        End If
        
        TempBMFH.bfSize = TempBMFH.bfOffBits + MyBMI.bmiHeader.biSizeImage
        
        ReDim TempBytes(1 To MyBMI.bmiHeader.biSizeImage)
        CopyMemory TempBytes(1), ByVal MyPtr, MyBMI.bmiHeader.biSizeImage
        
        FileNum = FreeFile
        
        Open FileName For Binary As #FileNum
        
        Put #FileNum, , TempBMFH
        Put #FileNum, , MyBMI.bmiHeader
        If MyBMI.bmiHeader.biBitCount <= 8 Then Put #FileNum, , TCB
        Put #FileNum, , TempBytes
        
        Close #FileNum
        
        SaveBMP = True
        
    End Function