透明叠加方式是图象处理中常用的一种处理方式,在这种处理方式中,一幅
图片叠加到另
一幅
图片上,但是这幅图象不是完全将原来的图象覆盖,而是能够部分的透过叠加的图象显示
出来,下面我就介绍如何在VB中编程实现这样的功能。
首先在建立两个大小相等的图象文件,将它们保存成BMP文件,VB5以上的版本支
持JPEG显示,也可以保存为Jpg文件。在Form中加入两个PictureBox控件,将它们的大小设置成
同图象文件相同的大小。注意这两个PictureBox控件不要相互重叠,也不要和Form中的其它控件
产生重叠。将两幅图象分别加入到两个PictureBox控件中。然后在Form中加入一个CommandButton
控件。最后在Form的代码窗口中加入以下代码:
Private Type LOGBRUSH
lbStyle As Long
lbColor As Long
lbHatch As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal _
hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) _
As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc _
As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, _
ByVal hObject As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, _
lpRect As RECT, ByVal hBrush 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 Declare Function CreateBrushIndirect Lib "gdi32" (lpLogBrush _
As LOGBRUSH) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Const SRCPAINT = &HEE0086
Const SRCAND = &H8800C6
Const BS_SOLID = 0
Const gColor = &HFFFFFF
Private Sub Command1_Click()
Dim pDstDC As Long
Dim dcCompatible As Long
Dim pBitmapOld As Long
Dim bm As Long
Dim rectTemp As RECT
Dim lBrush As Long
Dim tLog As LOGBRUSH
&nbs