Does anyone know how to play a GIF animation only once?
I’m using ImageAnimator class with a GIF animation that was designed with Animation Shop 3 to play or loop only once. When using the code below the animation starts looping repeatedly.
Does anyone know the right code to play this GIF animation one time only?
Thanks
Andy
This is the code I’m using:
'Create a Bitmpap Object.
Private WaterDropAnimation As New Bitmap("WaterDrop.gif"
Private currentlyAnimating As Boolean = False
'This method begins the animation.
Public Sub AnimateImage()
If Not currentlyAnimating Then
'Begin the animation only once.
ImageAnimator.Animate(WaterDropAnimation, New EventHandler(AddressOf Me.OnFrameChanged))
currentlyAnimating = True
End If
End Sub
Private Sub OnFrameChanged(ByVal o As Object, ByVal e As EventArgs)
'Force a call to the Paint event handler.
Me.Invalidate()
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
'Get the next frame ready for rendering.
ImageAnimator.UpdateFrames()
'WaterDropAnimation.MakeTransparent(WaterDropAnimation.GetPixel(0, 0))
'Draw the next frame in the animation.
e.Graphics.DrawImage(Me.WaterDropAnimation, New Point(125, 125))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Begin the animation.
AnimateImage()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If currentlyAnimating Then
'Begin the animation only once.
ImageAnimator.StopAnimate(WaterDropAnimation, New EventHandler(AddressOf Me.OnFrameChanged))
currentlyAnimating = False
End If
End Sub
I’m using ImageAnimator class with a GIF animation that was designed with Animation Shop 3 to play or loop only once. When using the code below the animation starts looping repeatedly.
Does anyone know the right code to play this GIF animation one time only?
Thanks
Andy
This is the code I’m using:
'Create a Bitmpap Object.
Private WaterDropAnimation As New Bitmap("WaterDrop.gif"
Private currentlyAnimating As Boolean = False
'This method begins the animation.
Public Sub AnimateImage()
If Not currentlyAnimating Then
'Begin the animation only once.
ImageAnimator.Animate(WaterDropAnimation, New EventHandler(AddressOf Me.OnFrameChanged))
currentlyAnimating = True
End If
End Sub
Private Sub OnFrameChanged(ByVal o As Object, ByVal e As EventArgs)
'Force a call to the Paint event handler.
Me.Invalidate()
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
'Get the next frame ready for rendering.
ImageAnimator.UpdateFrames()
'WaterDropAnimation.MakeTransparent(WaterDropAnimation.GetPixel(0, 0))
'Draw the next frame in the animation.
e.Graphics.DrawImage(Me.WaterDropAnimation, New Point(125, 125))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Begin the animation.
AnimateImage()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If currentlyAnimating Then
'Begin the animation only once.
ImageAnimator.StopAnimate(WaterDropAnimation, New EventHandler(AddressOf Me.OnFrameChanged))
currentlyAnimating = False
End If
End Sub