VB.NET Animated Gif to Bitmap, while retaining Anim

放肆的年华 提交于 2020-01-17 08:10:07

问题


I am coding using Visual Basic. I have a little problem however.

For my program, I need to layer GIFs/PNGs. I have accomplished this by using .DrawImage() It works fine however, the GIFs are inanimate and static.

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.

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

The above is the code that is supposed to animate the "(a)takingnotes.gif" (called as a resource).

It returns a static image of the first frame in the PictureBox.

Thank you!

EDIT: AnimateImage() is called on Load, which didn't work. I also tested on every Timer Tick, which also didn't work.

来源:https://stackoverflow.com/questions/29236265/vb-net-animated-gif-to-bitmap-while-retaining-anim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!