• Vui lòng đọc nội qui diễn đàn để tránh bị xóa bài viết
  • Tìm kiếm trước khi đặt câu hỏi

Hiệu ứng ApphaBlend

Các thủ thuật về âm thanh, đồ họa, truyền thông đa phương tiện...
tindl88
Thành viên tâm huyết
Thành viên tâm huyết
Posts: 363
Joined: Sat 26/04/2008 6:10 pm
Has thanked: 16 times
Been thanked: 10 times

Hiệu ứng ApphaBlend

Postby tindl88 » Wed 05/11/2008 9:54 am

Thủ thuật: Hiệu ứng ApphaBlend
Tác giả: Sưu tầm
Mô tả: Tạo hiệu ứng ApphaBlend giữa 2 hình


Code: Select all

  1. 'Thủ thuật AlphaBlend
  2. 'Cần 2 Timer (Timer1,Timer1) 2 PictureBox (Picture1, Picture2) 2 PictureBox này load 2 hình khác nhau.
  3.  
  4. Const AC_SRC_OVER = &H0
  5.  
  6. Private Type BLENDFUNCTION
  7.  BlendOp As Byte
  8.  BlendFlags As Byte
  9.  SourceConstantAlpha As Byte
  10.  AlphaFormat As Byte
  11. End Type
  12.  
  13. Private Declare Function AlphaBlend Lib "msimg32.dll" (ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal BLENDFUNCT As Long) As Long
  14. Private Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source As Any, ByVal Length As Long)
  15.  
  16. Dim BlendVal As Integer
  17. Dim BF As BLENDFUNCTION, lBF As Long
  18.  
  19. Dim tempPic1 As New StdPicture, tempPic2 As New StdPicture
  20.  
  21. Private Sub Form_Load()
  22.     With Picture1
  23.         .AutoRedraw = True
  24.         .ScaleMode = vbPixels
  25.     End With
  26.    
  27.     With Picture2
  28.         .AutoRedraw = True
  29.         .ScaleMode = vbPixels
  30.     End With
  31.  
  32.     'set the parameters
  33.     'AlphaBlend the picture from Picture1 over the picture of Picture2
  34.     BlendVal = 1
  35.     Set tempPic1 = Picture1.Picture
  36.     Set tempPic2 = Picture2.Picture
  37.  
  38.     With Timer1
  39.         .Interval = 60
  40.         .Enabled = True
  41.     End With
  42.    
  43.     With Timer2
  44.         .Interval = 60
  45.         .Enabled = False
  46.     End With
  47. End Sub
  48.  
  49. Private Sub Form_Unload(Cancel As Integer)
  50.     Timer1.Enabled = False
  51.     Timer2.Enabled = False
  52. End Sub
  53.  
  54. Public Sub DoAlphablend(SrcPicBox As PictureBox, DestPicBox As PictureBox, AlphaVal As Integer)
  55.     With BF
  56.         .BlendOp = AC_SRC_OVER
  57.         .BlendFlags = 0
  58.         .SourceConstantAlpha = AlphaVal
  59.         .AlphaFormat = 0
  60.     End With
  61.     'copy the BLENDFUNCTION-structure to a Long
  62.     RtlMoveMemory lBF, BF, 4
  63.     'AlphaBlend the picture from Picture1 over the picture of Picture2
  64.     AlphaBlend DestPicBox.hdc, 0, 0, DestPicBox.ScaleWidth, DestPicBox.ScaleHeight, SrcPicBox.hdc, 0, 0, SrcPicBox.ScaleWidth, SrcPicBox.ScaleHeight, lBF
  65. End Sub
  66.  
  67. Private Sub Timer1_Timer()
  68.     Picture1.Refresh
  69.     Picture2.Refresh
  70.  
  71.     BlendVal = BlendVal + 5
  72.     If BlendVal >= 155 Then
  73.         Flag = True
  74.         Timer1.Enabled = False
  75.         Picture2.Picture = tempPic1
  76.         Timer2.Enabled = True
  77.         BlendVal = 1
  78.     End If
  79.  
  80.     DoAlphablend Picture2, Picture1, BlendVal
  81.  
  82.     Me.Caption = CStr(BlendVal)
  83. End Sub
  84.  
  85. Private Sub Timer2_Timer()
  86.     Picture1.Refresh
  87.     Picture2.Refresh
  88.  
  89.     BlendVal = BlendVal + 5
  90.     If BlendVal >= 155 Then
  91.         BlendVal = 1
  92.         Timer1.Enabled = True
  93.         Timer2.Enabled = False
  94.         Picture2.Picture = tempPic2
  95.     End If
  96.     DoAlphablend Picture2, Picture1, BlendVal
  97.  
  98.     Me.Caption = CStr(BlendVal)
  99. End Sub
  100.  
  101.  


cứng nhắc...vớ vẩn

Return to “[VB] Âm thanh và Đồ họa”

Who is online

Users browsing this forum: No registered users and 0 guests