title: VB.NET Animated Gif to Bitmap, while retaining Anim
body: <p>I am coding using Visual Basic. I have a little problem however.</p>
  
  <p>For my program, I need to layer GIFs/PNGs. I have accomplished this by using <code>.DrawImage()</code> It works fine however, the GIFs are inanimate and static.</p>
  
  <p>I have tried using the ImageAnimator Class, however, I am a bit in the dark. I tried using the sample code from MSDN, and it is not working for me. This is probably because I don't quite understand it.</p>
  
  <pre><code>Private animatedImage As New Bitmap(My.Resources._a_takingnotes)
  Private currentlyAnimating As Boolean = False
  
  
  Public Sub AnimateImage()
      If Not currentlyAnimating Then
  
          'Begin the animation only once.
          ImageAnimator.Animate(animatedImage, _
          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)
  
      'Begin the animation.
      AnimateImage()
  
      'Get the next frame ready for rendering.
      ImageAnimator.UpdateFrames()
  
      'Draw the next frame in the animation.
      e.Graphics.DrawImage(Me.animatedImage, New Point(0, 0))
      PictureBox2.Image = Nothing
      PictureBox2.Image = animatedImage
  End Sub
  </code></pre>
  
  <p>The above is the code that is supposed to animate the "(a)takingnotes.gif" (called as a resource). </p>
  
  <p>It returns a static image of the first frame in the PictureBox.</p>
  
  <p>Thank you!</p>
  
  <p><em>EDIT</em>: <code>AnimateImage()</code> is called on Load, which didn't work. I also tested on every Timer Tick, which also didn't work.</p>