Image Animation in VB.NET using GDI+
This article demonstrate you to implement different types of animations or transitions on images with the help of VB.NET using GDI+.
In this article you will learn how to implement different animation effects or you can say transitions on images with the help of VB.NET using GDI+. You can make your slide shows, business presentations, videos, and screensavers more attractive and beautiful using transitions on the web pages/Windows Forms/videos with simple and very easy code.
Annimation Effect on Image in VB.NET using GDI+
Here we apply a simple light-weight timer implemented by the System.Threading.Timer that uses callback functions. Then we declare timer and hook up the Elapsed event for the timer and enable the timer.
Private Sub TimerTick(ByVal source As Object, ByVal e As System.Timers.ElapsedEventArgs)
Dim ts As TimeSpan = DateTime.Now - m_AnimationStartTime
m_AnimationPercent = CSng((100.0F / m_AnimationSpeed.TotalSeconds * ts.TotalSeconds))
If m_AnimationPercent > 100 Then
m_AnimationPercent = 100
End If
Invalidate()
End Sub
The following code example illustrates how to give effects to image slides from bottom left to top right:
Protected Sub DrawAnimatedImage(ByVal g As Graphics, ByVal control As AnimationControl)
If m_AnimatedBitmap IsNot Nothing Then
Select Case m_AnimationType
Case AnimationTypes.BottomLeftToTopRight ' Image effect
Dim mx As New Drawing2D.Matrix(1, 0, 0, 1, (control.Width * m_AnimationPercent / 100) - control.Width, -(control.Height * m_AnimationPercent / 100) + control.Height)
g.Transform = mx
g.DrawImage(m_AnimatedBitmap, control.ClientRectangle, 0, 0, m_AnimatedBitmap.Width, m_AnimatedBitmap.Height, GraphicsUnit.Pixel)
mx.Dispose()
Exit Select
End Select
End If
If m_AnimationPercent = 100 Then
AnimationStop()
End If
End Sub
Now when you click on Slide button the image will come as a slide like this:
Split Boom Animation