B4J Library GIFdecoder Library - Released

I needed to access the frames in a GIF file by their frame index so I could extract and display each frame in any order, as I required, not just play the GIF animation itself.

I found that B4X user max123 had already begun converting the B4A library (of the same name) several years ago.
max123 Original Post: GifDecoder library for B4J
Unfortunately, it remained unfinished as he requested help in resolving the many conversion issues he had en counted, but did not receive any interest from other B4X users.

Although I am "Late to the Party" I have made the necessary changes to get this library running properly under B4J.

See below for the Current Release of jGIFdecoder library.

Here is a simple B4J test project so you can see how easy it is to use.
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    
    Dim gif As GifDecoder
    Private img1 As ImageView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    MainForm.BackColor = fx.Colors.LightGray
    MainForm.Title = "B4J GIFdecoder Test"
    
    gif.Load(File.DirAssets,"animated.gif")

    Log ("Number of Frames: " & gif.NumberOfFrames)
    Log ("Width: " & gif.Width)
    Log ("Height: " & gif.Height)
    Log ("LoopCount: " & gif.LoopCount)
    
    img1.Initialize("img1")
    MainForm.RootPane.AddNode(img1, 50, 50, gif.Width, gif.Height)

    Dim I As Int = 0
    Do Until False
        If I = gif.NumberOfFrames Then I = 0
        img1.SetImage(gif.FrameImage(I))
        'gif.SaveFrame(I, "C:\Users\me\Desktop\test", "frame" & I & ".png")
        Dim D As Int = gif.FrameDelay(I)
        'Log("Delay= " & D)
        Sleep(D)
        I=I+1
    Loop
    
    gif.DisposeAllFrames
End Sub

Note: I have included two small GIF files in the project's assets but for the more ambitious , try downloading this LARGE animated GIF file and play it with the B4J GifDecoder Test project.
 

Attachments

  • jGifDecoder Library 1.02.zip
    8.3 KB · Views: 257
  • B4J GifDecoder Test.zip
    424.8 KB · Views: 245

max123

Well-Known Member
Licensed User
Longtime User
Great work Scott. I've tried it with big animated gifs and works like a charm ;) ;)
 
Top