代码很简单,就不解释了,演示VB如何实现两幅图片半透明叠加的效果。
Option Explicit Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function DeleteDC 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 DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long 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 Sub Form_Load() Dim w As Long,h As Long Dim Pic1 As StdPicture,Pic2 As StdPicture Dim hMemDc1 As Long,hMemDc2 As Long Dim hOldBmp1 As Long,hOldBmp2 As Long Set Pic1 = LoadPicture("c:/pic1.jpg") hMemDc1 = CreateCompatibleDC(Me.hdc) hOldBmp1 = SelectObject(hMemDc1,Pic1.Handle) Set Pic2 = LoadPicture("c:/pic2.jpg") w = Me.ScaleX(Pic2.Width,vbHimetric,vbPixels) h = Me.ScaleY(Pic2.Height,vbPixels) hMemDc2 = CreateCompatibleDC(Me.hdc) hOldBmp2 = SelectObject(hMemDc2,Pic2.Handle) AlphaBlend hMemDc1,w,h,hMemDc2,100 * &H10000 DeleteObject SelectObject(hMemDc2,hOldBmp2) DeleteDC hMemDc2 Set Pic2 = Nothing SelectObject hMemDc1,hOldBmp1 DeleteDC hMemDc1 Set Me.Picture = Pic1 Set Pic1 = Nothing End Sub