|
-
Jan 2nd, 2011, 06:08 PM
#1
Thread Starter
Hyperactive Member
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!
-
Jan 2nd, 2011, 07:39 PM
#2
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
-
Jan 2nd, 2011, 08:13 PM
#3
Re: Fade image in and out
 Originally Posted by LaVolpe
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.
-
Jan 2nd, 2011, 08:18 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|