Results 1 to 4 of 4

Thread: Fade image in and out

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Canada
    Posts
    297

    Fade image in and out

    Hi folks,

    I've been trying to find the best way to fade an image in and then out again, but all my research has yielded were options to fade between two images, but I'd much rather like to know if anyone has a method to just fade one image in, then out.

    I'm not too familiar with control transparencies, so I'm hoping someone will be able to help me with this.

    Specifically, I'm working with a small Image box, not a Picture box.

    Any help is appreciate, thanks!

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Fade image in and out

    There is no such thing as control transparencies, not really. Fading can be done using a backbuffer to hold the original image (whether its an memory bitmap or hidden picturebox with AutoRedraw=True). Either way, you'd want to use AlphaBlend API. You're not going to be able to fade an image control

    The idea is via use of a timer or a DoEvents loop
    1) Clear area to be drawn
    2) Use AlphaBlend to render image at a reduced opacity
    3) Pause & repeat as needed

    Try searching forum for: fade picture
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Fade image in and out

    Quote Originally Posted by LaVolpe View Post
    There is no such thing as control transparencies, not really. Fading can be done using a backbuffer to hold the original image (whether its an memory bitmap or hidden picturebox with AutoRedraw=True). Either way, you'd want to use AlphaBlend API. You're not going to be able to fade an image control

    The idea is via use of a timer or a DoEvents loop
    1) Clear area to be drawn
    2) Use AlphaBlend to render image at a reduced opacity
    3) Pause & repeat as needed

    Try searching forum for: fade picture
    Thanks, Fox. I would have liked to have done this about 5 to 10 years ago. I love fade-in and fade-out for images and so did my sponsors. I had no idea that it was available back then. Dang it. I missed the boat.
    Doctor Ed

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Fade image in and out

    Canadian Weather Man, if you'd like to play with my Alpha Image Control. It can do what you are asking, but the control may be overkill for what you need. See it linked in my signature below. To fade, sample code might look like:
    Code:
    Private Sub Command1_Click()
         Timer1.Tag = "FadeOut"
         Timer1.Interval = 60 ' ?? 
         Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
       If Timer1.Tag = "FadeOut" Then
            AlphaImgCtl1.TransparencyPct = AlphaImgCtl1.TransparencyPct + 10 ' step at 10%
            If AlphaImgCtl1.TransparencyPct = 100 Then Timer1.Tag = "Pause"
       ElseIf Timer1.Tag = "Pause" Then
            Timer1.Tag = "FadeIn" ' fade back in now
       Else
            AlphaImgCtl1.TransparencyPct = AlphaImgCtl1.TransparencyPct - 10 ' step back 10%
            If AlphaImgCtl1.TransparencyPct = 0 Then Timer1.Enabled = False ' done; stop timer
       End If
    End Sub
    Edited: Modified sample routine for a complete fade out then fade in
    Last edited by LaVolpe; Jan 2nd, 2011 at 08:45 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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