- LuckySXyd
-
打开VB建立一个新工程。选择 菜单-工程-添加模块 添加一个模块到工程中,在其中输入以下代码:
Public Type rBlendProps
tBlendOp As Byte
tBlendOptions As Byte
tBlendAmount As Byte
tAlphaType As Byte
End Type
Public Declare Function AlphaBlend Lib "msimg32" (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 widthSrc As Long, _
ByVal heightSrc As Long, ByVal blendFunct As Long) As Boolean
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)
在Form1中添加两个PictureBox控件,其中Picture2为源,Picture1为拷贝目标,将两者的ScaleMode都设置为3-Pixel将两者的AutoRedraw属性都设置为True,然后分别添加图像。在加入一个Slider控件,然后在Form1的代码窗口中添加如下代码:
Sub ShowTransparency(cSrc As PictureBox, cDest As PictureBox, _
ByVal nLevel As Byte)
Dim LrProps As rBlendProps
Dim LnBlendPtr As Long
cDest.Cls
LrProps.tBlendAmount = nLevel
CopyMemory LnBlendPtr, LrProps, 4
With cSrc
AlphaBlend cDest.hDC, 0, 0, .ScaleWidth, .ScaleHeight, _
.hDC, 0, 0, .ScaleWidth, .ScaleHeight, LnBlendPtr
End With
cDest.Refresh
End Sub
Private Sub Form_Load()
Picture2.Picture = LoadPicture("D:a.jpg") "源图片路径
Slider1.Max = 100
Slider1.Min = 0
End Sub
Private Sub Slider1_Click()
ShowTransparency Picture2, Picture1, Slider1.Value * 2.5
End Sub