''注释:取得 hInvertMaskDC 的自订函数,该hMaskDC内的图像是souImg图之背景为白色
''注释: 而souImg的前景图是黑色
''注释:PicBack 叁数: 用来制作 Mask 图的图片盒
''注释:souImg 叁数: 摆放原图的影像之物件,可以是 image/picturebox
''注释:TColor 叁数: 欲去除的颜色,即souImg的背景色
Public Sub GetInvertMaskPic(picBack As PictureBox, _
souImg As Control, ByVal TColor As Long)
Dim hdcMono, hbmpMono, hbmpOld
Dim ColorBack As Long
Dim dx As Single, dy As Single
With picBack
dx = .ScaleX(souImg.Picture.Width, vbHimetric, vbPixels)
dy = .ScaleY(souImg.Picture.Height, vbHimetric, vbPixels)
''注释: 设定pictureBox的大小与Source Image的大小相同
.Width = souImg.Width
.Height = souImg.Height
Set .Picture = souImg.Picture
End With
hdcMono = CreateCompatibleDC(0)
hbmpMono = CreateCompatibleBitmap(hdcMono, dx, dy)
hbmpOld = SelectObject(hdcMono, hbmpMono)
picBack.AutoRedraw = True
picBack.BackColor = RGB(255, 255, 255)
ColorBack = SetBkColor(picBack.hDc, TColor)
BitBlt hdcMono, 0, 0, dx, dy, picBack.hDc, 0, 0, vbSrcCopy
Call SetBkColor(picBack.hDc, ColorBack)
BitBlt picBack.hDc, 0, 0, dx, dy, hdcMono, 0, 0, vbNotSrcCopy
hInvertMaskDC = CreateCompatibleDC(0)
hBmpInvertMask = CreateCompatibleBitmap(picBack.hDc, dx, dy)
Call SelectObject(hInvertMaskDC, hBmpInvertMask)
BitBlt hInvertMaskDC, 0, 0, dx, dy, picBack.hDc, 0, 0, vbSrcCopy
&nbs