Dim sth() As Byte
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As LongPrivate Sub Command1_Click()
Open "c:\fy.jpg" For Binary As #1
i = FileLen("c:\sth.bmp")
ReDim sth(i - 1) As Byte
Get #1, , sth
Close #1
a = SetBitmapBits(Picture1.hDC, i, sth(0))   '不能这样用吧
End Sub
我想把图片通过SetBitmapBits放到picture1上
应该怎么使用
请指教

解决方案 »

  1.   

    给你一个例子:'Create a new project, add a command button and a picture box to the project, load a picture into the picture box.
    'Paste this code into Form1
    Private Type BITMAP
        bmType As Long
        bmWidth As Long
        bmHeight As Long
        bmWidthBytes As Long
        bmPlanes As Integer
        bmBitsPixel As Integer
        bmBits As Long
    End Type
    Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
    Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
    Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
    Dim PicBits() As Byte, PicInfo As BITMAP
    Dim Cnt As Long, BytesPerLine as Long
    Private Sub Command1_Click()    'Get information (such as height and width) about the picturebox
        GetObject Picture1.Image, Len(PicInfo), PicInfo
        'reallocate storage space
        BytesPerLine = (PicInfo.bmWidth * 3 + 3) And &HFFFFFFFC
        ReDim PicBits(1 To BytesPerLine * PicInfo.bmHeight * 3) As Byte
        'Copy the bitmapbits to the array
        GetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
        'Invert the bits
        For Cnt = 1 To UBound(PicBits)
            PicBits(Cnt) = 255 - PicBits(Cnt)
        Next Cnt
        'Set the bits back to the picture
        SetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
        'refresh
        Picture1.Refresh
    End Sub
    SHANNON
       ----------------
        [email protected]
      

  2.   

    【声明】
    Public Declare Function SetBitmapBits Lib "gdi32" Alias "SetBitmapBits" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
    【说明】
    将来自缓冲区的二进制位复制到一幅位图
    【返回值】
    Long,执行成功则返回字节数量,零表示失败
    【参数表】
      hBitmap --------  Long,位图的句柄  dwCount --------  Long,欲复制的字节数量  lpBits ---------  Any,指向一个缓冲区的指针。这个缓冲区包含了为位图正确格式化的位图位
    【其它】
    在Win32中,应使用与设备无关位图
      

  3.   

    http://expert.csdn.net/Expert/topic/1714/1714165.xml?temp=.1287653