3

Is it possible, without an external code library, to separate a .gif file into its individual frames, and conversely, to assemble a group of images into one?

I have spent a while playing with the System.Drawing namespace, and cannot seem to figure out how.

Also, I cannot figure out what to pass as a parameter for GetFrameCount. I do not know what they mean by a "dimension", and apparently it cannot be left null.

Additionally, is it possible to have playback control over the gif without first splitting it and recompiling/displaying in a way that mimics playback?

Thanks for the help.

This is in vb.net, 2008.

EDIT: If it is not possible without an external library, what is the best one to use?

4

2 回答 2

4

我使用了与此类似的代码,它工作得很好......我没有发明它,所以感谢做过的人(我已经忘记了)......(也许在这里)。

Private Class Frame
    Public Property MilliSecondDuration As Integer
    Public Property Bitmap As Image
    Public Sub New(ByVal duration As Integer, ByVal img As Bitmap)
        Me.MilliSecondDuration = duration
        Me.Bitmap = img
    End Sub
End Class

Private Function SeparateGif() As Frame()

    Dim gif As Image = Image.FromFile("MyGif.gif")

    Dim fd As New Imaging.FrameDimension(gif.FrameDimensionsList()(0))
    Dim frameCount As Integer = gif.GetFrameCount(fd)
    Dim frames(frameCount) As Frame

    If frameCount > 1 Then
        Dim times() As Byte = gif.GetPropertyItem(&H5100).Value
        For i As Integer = 0 To frameCount - 1
            gif.SelectActiveFrame(fd, i)
            Dim length As Integer = BitConverter.ToInt32(times, 4 * i) * 10
            frames(i) = New Frame(length, New Bitmap(gif))
        Next
    End If

    Return frames

End Function
于 2011-01-13T09:36:12.653 回答
0

According to this forum post saving the animated GIF is not supported in .NET. So no, without an external code library, it's likely not possible.

Any particular reason you're averse to external libs?

于 2009-09-07T02:20:02.297 回答