设Form1 中有两个picturebox 空间 名称分别是 p1,p2
设p1的picture属性是"c:\1.jpg",p2的picture属性是"c:\2.jpg" 图片的大小属性是250*150
现在要将 p2中的的图片显示在p1中,只用BitBlt方法,怎么实现啊!
dl& = BitBlt(Picture1.hDC, 0, 0, 250, 150, Picture2.hDC, 0, 0, 0)还有啊 ,光栅的概念是什么?又是怎么用的 啊!
谢谢先啦!!

解决方案 »

  1.   

    Private Sub Command1_Click()
        Picture2.AutoRedraw = True
        Picture2.Width = Picture1.Width
        Picture2.Height = Picture1.Height
        BitBlt Picture2.hDC, 0, 0, Picture2.Width, Picture2.Height, Picture1.hDC, 0, 0, vbSrcCopy
        Picture2.AutoRedraw = False
        Picture2.Refresh
    End Sub
      

  2.   

    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    Private Const SRCAND = &H8800C6  ' (DWORD) dest = source AND dest
    Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
    Private Declare Function CreatePatternBrush Lib "gdi32" (ByVal hbitmap As Long) As Long
    Dim hbitmap As Long, hpattern As LongPrivate Sub Command1_Click()
    Dim bbmp(0 To 15) As Byte
    bbmp(0) = &H33: bbmp(2) = &H0
    bbmp(4) = &H33: bbmp(6) = &H0
    bbmp(8) = &H33: bbmp(10) = &H0
    bbmp(12) = &H33: bbmp(14) = &H0hbitmap = CreateBitmap(8, 8, 1, 1, bbmp(0))
    hpattern = CreatePatternBrush(hbitmap)Picture1.Refresh
    holdpattern = SelectObject(Picture2.hdc, hpattern)
    BitBlt Picture2.hdc, 0, 0, Picture2.Width, Picture2.Height, Picture1.hdc, 0, 0, SRCAND
    DeleteObject hbitmap
    DeleteObject hpattern
    SelectObject Picture2.hdc, holdpattern
    End Sub
      

  3.   

    BitBlt Picture1.hDC, 0, 0, 250, 150, Picture2.hDC, 0, 0, vbsrccopy
    Picture1的AutoReDraw属性都应为True,不然绘制的图片不能保留。
    光栅操作有很多种,
    vbsrccopy就是简单的将源图向目标图复制,还有常用的如:
    vbSrcAnd 用 And 运算合并目标像素与源位图 
    vbSrcErase 反转目标位图并用 And 运算合并所得结果与源位图 
    vbSrcInvert 用 Xor 运算合并目标像素和源位图 
    vbSrcPaint 用 Or 运算合并目标像素和源位图