Results 1 to 2 of 2

Thread: Best Fade Method

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210

    Best Fade Method

    I am trying to fade between two pictures. They each have their own Picture box and i am updating a third that contains the fading. I am using GetPixel and SetPixel, but it is really slow. Are there any faster methods of fading?

    Thanks
    -George
    < o >

  2. #2
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    Create a Slider and set the min to 0 and the mex to 255
    this code will fade the picture1 and picture3 into picture2

    VB Code:
    1. Option Explicit
    2. Const AC_SRC_OVER = &H0
    3. Private Type BLENDFUNCTION
    4.   BlendOp As Byte
    5.   BlendFlags As Byte
    6.   SourceConstantAlpha As Byte
    7.   AlphaFormat As Byte
    8. End Type
    9. 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
    10. Private Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source As Any, ByVal Length As Long)
    11. Private Sub Slider1_Change()
    12.     Dim BF As BLENDFUNCTION, lBF As Long
    13.     Picture2.Picture = Picture3.Picture
    14.     'set the parameters
    15.     With BF
    16.         .BlendOp = AC_SRC_OVER
    17.         .BlendFlags = 0
    18.         .SourceConstantAlpha = Slider1.Value
    19.         .AlphaFormat = 0
    20.     End With
    21.     'copy the BLENDFUNCTION-structure to a Long
    22.     RtlMoveMemory lBF, BF, 4
    23.     AlphaBlend Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, lBF
    24.     Picture2.Refresh
    25.    
    26. End Sub
    Last edited by cyborg; Nov 24th, 2002 at 12:22 PM.
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width