关于alphablend函数
如果一个32位dib对象,每个象素的第4个字节,应该是表示透明度的,等于0,我认为好像是完全透明了,然后再用alphablend函数将这个dib位图显示出来,发现即使alpha=0也不能完全透明,这是怎么回事。 --------------------编程问答-------------------- '添加 Command1 Command2 Timer1 Picture1 Picture2'Picture1与 Picture2各别加上一张图片 Picture1的图片比Picture2的图片大一点比较能看出效果
Private Type rBlendProps
tBlendOp As Byte
tBlendOptions As Byte
tBlendAmount As Byte
tAlphaType As Byte
End Type
Private 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
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Dim lTime As Byte, fadeio%
Private Sub Form_Load()
Picture1.ScaleMode = 3: Picture1.AutoRedraw = True: BorderStyle = 0
Picture2.ScaleMode = 3: Picture2.AutoRedraw = True: BorderStyle = 0
Command1.Caption = "淡 进"
Command2.Caption = "淡 出"
Command1_Click
End Sub
Private Sub Command1_Click()
fadeio = 1: lTime = 0
Timer1.Interval = 100: Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
fadeio = 2: lTime = 255
Timer1.Interval = 100: Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
lTime = IIf(fadeio = 1, lTime + 3, lTime - 3)
If lTime >= 255 Then lTime = 255: Timer1.Enabled = False
If lTime <= 0 Then lTime = 0: Timer1.Enabled = False
ShowTransparency Picture2, Picture1, lTime
End Sub
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
'两张图片淡进淡出的效果图
http://p.blog.csdn.net/images/p_blog_csdn_net/cbm666/366646/o_AlphaBlend.jpg
--------------------编程问答-------------------- UP
补充:VB , API