动画GIF不会停止循环Winforms

Spa*_*awk 3 vb.net visual-studio-2010 winforms

我的窗体上的PictureBox中有一个动画gif,但是它总是循环播放,如何使它只播放一次?

在其他程序(例如浏览器)中查看gif时,它只会播放一次,应该播放一次。但是在我的窗体上,它始终循环播放,动画循环之间只有非常短的抖动停顿。

the*_*eGD 5

这花了我一段时间。在这里,我得到了一些帧,并对gif进行动画处理,直到帧结束。

Public Class Form1

    Dim animatedImage As New Bitmap("a.gif")
    Dim currentlyAnimating As Boolean = False
    Dim framecounter As Integer = 0
    Dim framecount As Integer
    Dim framdim As Imaging.FrameDimension
    Private Sub OnFrameChanged(ByVal o As Object, ByVal e As EventArgs)
        PictureBox1.Invalidate()
    End Sub

    Sub AnimateImage()
        If Not currentlyAnimating Then
            ImageAnimator.Animate(animatedImage, New EventHandler(AddressOf Me.OnFrameChanged))
            currentlyAnimating = True
        End If
    End Sub

    Private Sub PictureBox1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        If framecounter < framecount Then
            AnimateImage()
            ImageAnimator.UpdateFrames()
            e.Graphics.DrawImage(Me.animatedImage, New Point(0, 0))
            framecounter += 1
        End If
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        framdim = New Imaging.FrameDimension(animatedImage.FrameDimensionsList(0))
        framecount = animatedImage.GetFrameCount(framdim)
    End Sub

End Class
Run Code Online (Sandbox Code Playgroud)