Private Declare Function BitBlt Lib "gdi32" (ByVal hdcDest _ As Long, ByVal xDest As Long, ByVal yDest As Long, _ ByVal nWidth As Long, ByVal nHeight As Long, ByVal _ hdcSrc As Long, ByVal xSrc As Long, ByVal ySrc As Long, _ ByVal dwRop As Long) As Long |
Private Sub Command1_Click() Dim hdc1 As Long, hdc2 As Long 'デバイスコンテキスト Dim hdc3 As Long, hdc4 As Long Dim pw As Long, ph As Long 'コピー元の領域の幅,高さ Dim sx As Long, sy As Long 'コピー先の始点 pw = 32&: ph = 32& '&記号は長整数型の指定 sx = 50&: sy = 50& hdc1 = Picture1.hDC: hdc2 = Picture2.hDC hdc3 = Picture3.hDC: hdc4 = Picture4.hDC 'まず、コピー先の背景の位置をコピーしておく BitBlt hdc4, 0&, 0&, pw, ph, hdc1, sx, sy, vbSrcCopy 'その部分に、特定部分が白でその他が黒のものを論理Andさせる BitBlt hdc4, 0&, 0&, pw, ph, hdc3, 0&, 0&, vbSrcAnd 'さらに、それに対し特定部分を論理Or結合させる BitBlt hdc4, 0&, 0&, pw, ph, hdc2, 0&, 0&, vbSrcPaint 'コピー先にコピーする BitBlt hdc1, sx, sy, pw, ph, hdc4, 0&, 0&, vbSrcCopy End Sub |
BitBlt hdc4, 0&, 0&, pw, ph, hdc2, 0&, 0&, vbSrcPaint の部分は、
BitBlt hdc4, 0&, 0&, pw, ph, hdc2, 0&, 0&, vbSrcInvert のようにしても、
同じようにコピーできます。