'This project needs 2 pictureboxes
'Picturebox1 must contain a picture with a lot of white pixels (we're going to use white as transparent color)
Private Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean
Private Sub Form_Load()
Picture1.AutoSize = True
'API uses pixels
Picture1.ScaleMode = vbPixels
Picture2.ScaleMode = vbPixels
End Sub
Private Sub Picture2_Paint()
'If we don't call DoEvents first, our transparent image will be completely wrong
DoEvents
TransparentBlt Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, vbWhite
End Sub
【声明】
Private Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (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
【说明】
将一幅位图从一个设备场景复制到另一个。源和目标DC相互间必须兼容
【返回值】
Long,非零表示成功,零表示失败。会设置GetLastError
【参数表】
hDestDC -------- Long,目标设备场景
我觉得用PAINTPICTURE方法比较简单,你可以用下列方法来自动加载图像,且只要使用一个PICTUREBOX控件:
DIM PIC AS STDPICTURE
SET PIC=LOADPICTURE("图片路径及名称")
然后用PICTUREBOX的PAINTPICTURE方法来家载图片,图片源就是PIC对象