B4A Library Animated GIF decode library

Attachments

  • GifDecoder1.0.zip
    29.9 KB · Views: 4,374
Last edited by a moderator:

zeuspower

Member
Licensed User
Longtime User
well,apparently the problem was from the Timer...
Beacause i use sliding panels,something was happening to Timer when i was changing panels...

So everytime i slide panels i Pause the Timer,and everything works OK
 

zeuspower

Member
Licensed User
Longtime User
nop...it does not work OK

It seems that it worked but after some repeats of choosing other exercises I have the same error...

I think the problem is on the GIF.LOAD execution,i isolated the sub to this :

B4X:
   Sub first_load_picture
         Dim what_picture As String
      
      gif.DisposeFrames
      
      
      If number_askisis=1 Then what_picture="BBBenchPress-no1.gif"
      If number_askisis=2 Then what_picture="BBInclineBenchPress-no2.gif"
      If number_askisis=3 Then what_picture="BBDeclineBenchPress-no3.gif"
      If number_askisis=4 Then what_picture="DBBenchPress-no4.gif"
      If number_askisis=5 Then what_picture="DBDeclineBenchPress-no5.gif"
      If number_askisis=6 Then what_picture="DBInclineBenchPress-no6.gif"
      If number_askisis=7 Then what_picture="DBPullover-no7.gif"
      If number_askisis=8 Then what_picture="DBFly-no8.gif"
       
      If number_askisis=9 Then what_picture="BBDeadlift-no9.gif"
      If number_askisis=10 Then what_picture="Clean-no10.gif"
      If number_askisis=11 Then what_picture="WTChinUp-no11.gif"
      If number_askisis=12 Then what_picture="WTpullUp-no12.gif"
      If number_askisis=13 Then what_picture="WTRearPullup-no13.gif"
      If number_askisis=14 Then what_picture="CBFrontPulldown-no14.gif"
      If number_askisis=15 Then what_picture="DBBentoverRow-no15.gif"
      If number_askisis=16 Then what_picture="BBBentOverRow-no16.gif"
      
      If number_askisis=17 Then what_picture="BBFullSquat-no17.gif"
      If number_askisis=18 Then what_picture="BBFrontSquat-no18.gif"
      If number_askisis=19 Then what_picture="BBLungeQuad-no19.gif"
      If number_askisis=20 Then what_picture="SL45DegLegPressQuad-no20.gif"
      If number_askisis=21 Then what_picture="SLHackSquatQuad-no21.gif"
      If number_askisis=22 Then what_picture="BBGoodMorning-no22.gif"
      If number_askisis=23 Then what_picture="LVSeatedLegCurl-no23.gif"
      
         gif.Load(File.DirAssets,what_picture)
         
         End Sub

no timer,no nothing...it crashes on the GIF.LOAD ,sometimes it takes 7-8 new GIF loadings,some other it crashes after 2 images...

why ?
with the gif.dispose ,it should'nt be any memory problems
the smallest gif is about 60k and the biggest about 250k ,is this the problem ?
it can't handle big gif ? and after sometime crashes ?
 

zeuspower

Member
Licensed User
Longtime User
OK,HERE IT IS,WORKS FOR SOME TIME ,THEN IT CRASHES...
AFTER THE ERROR,I CONTINUE THE APPLICATION AND AFTER 2-3 DIFFERENT CHOICES WILL CRASH AGAIN:


B4X:
LogCat connected to: 80A354043048387726
--------- beginning of /dev/log/system
 --------- beginning of /dev/log/main
 <!>anywheresoftware.b4a.keywords.Common 153<!> ** Activity (main) Create, isFirst = true **
 <!>anywheresoftware.b4a.keywords.Common 153<!> Warning: Panel.LoadLayout called with zero sized panel.
 <!>anywheresoftware.b4a.keywords.Common 153<!> Warning: Panel.LoadLayout called with zero sized panel.
 <!>anywheresoftware.b4a.keywords.Common 153<!> Warning: Panel.LoadLayout called with zero sized panel.
 <!>anywheresoftware.b4a.keywords.Common 153<!> Warning: Panel.LoadLayout called with zero sized panel.
 <!>anywheresoftware.b4a.keywords.Common 153<!> Warning: Panel.LoadLayout called with zero sized panel.
 <!>anywheresoftware.b4a.keywords.Common 153<!> ** Activity (main) Resume **

 <!>anywheresoftware.b4a.keywords.Common 153<!> 1    <<< WORKS
 <!>anywheresoftware.b4a.keywords.Common 153<!> 2    <<< WORKS
 <!>anywheresoftware.b4a.keywords.Common 153<!> 4    <<< WORKS
 <!>anywheresoftware.b4a.keywords.Common 153<!> 6  <<< IT CRASHES HERE

 <!>anywheresoftware.b4a.BA 466<!> main_first_load_picture (java line: 928)
 <!>anywheresoftware.b4a.BA 466<!> java.lang.ArrayIndexOutOfBoundsException
    at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.SetPixels(GifDecoder.java:390)
   at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.ReadImage(GifDecoder.java:805)
   at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.ReadContents(GifDecoder.java:672)
   at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.Read(GifDecoder.java:559)
   at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.Load(GifDecoder.java:211)
   at o.ntoulapas.main._first_load_picture(main.java:928)
   at o.ntoulapas.main._listview1_itemclick(main.java:1066)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   at anywheresoftware.b4a.BA$2.run(BA.java:266)
   at android.os.Handler.handleCallback(Handler.java:587)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:123)
   at android.app.ActivityThread.main(ActivityThread.java:3729)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
   at dalvik.system.NativeStart.main(Native Method)
<!>anywheresoftware.b4a.BA 466<!> java.lang.ArrayIndexOutOfBoundsException

<!>anywheresoftware.b4a.keywords.Common 153<!> 5       <<<WORKS OK
 <!>anywheresoftware.b4a.keywords.Common 153<!> 2   <<<WORKS OK
 <!>anywheresoftware.b4a.keywords.Common 153<!> 12     <<< IT CRASHES HERE

 <!>anywheresoftware.b4a.BA 466<!> main_first_load_picture (java line: 928)
 <!>anywheresoftware.b4a.BA 466<!> java.lang.ArrayIndexOutOfBoundsException
   at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.SetPixels(GifDecoder.java:390)
   at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.ReadImage(GifDecoder.java:805)
   at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.ReadContents(GifDecoder.java:672)
   at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.Read(GifDecoder.java:559)
   at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.Load(GifDecoder.java:211)
   at o.ntoulapas.main._first_load_picture(main.java:928)
   at o.ntoulapas.main._listview1_itemclick(main.java:1066)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   at anywheresoftware.b4a.BA$2.run(BA.java:266)
   at android.os.Handler.handleCallback(Handler.java:587)
   at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:123)
   at android.app.ActivityThread.main(ActivityThread.java:3729)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
   at dalvik.system.NativeStart.main(Native Method)
<!>anywheresoftware.b4a.BA 466<!> java.lang.ArrayIndexOutOfBoundsException
 

zeuspower

Member
Licensed User
Longtime User
I tried with another set of Gifs ,much smaller,only 2 images each gif ...
but I have the same problems...

sometimes works fine for 5-6 different choices,sometimes crashes on the 3rd gif...


no matter the gifs it will crash sooner or later...
I think that somewhere in the 'cycle" is the problem...
 

coslad

Well-Known Member
Licensed User
Longtime User
HI ,
i'm tring to port the sample code to my project but at the timer sub it crash with this error :

java.lang.NullPointerException
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:104)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)


the timer code is this :

B4X:
Sub Timer1_Tick
    Timer1.Enabled = False
    Frame = Frame + 1
    If Frame >= gif.FrameCount Then
        Frame = 0
    End If
    Timer1.Interval = gif.Delay(Frame)   
    immagine_animazione.Bitmap = gif.Frame(Frame)
    Timer1.Enabled = True
End Sub

i tried even with other gif like "clonesheep.gif" but nothing .

can you help me ?
Thanks
 

coslad

Well-Known Member
Licensed User
Longtime User
yes , the Timer is declered in the process global!

BUT ................

the problem was that Agraham in the code wrote :
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Timer1 As Timer
    Dim Frame As Int
    Timer1.Initialize("Timer1",0)
End Sub

The 'Timer1.Initialize("Timer1",0)' has not to be there .
Moving the initialize in the activity create everything works fine.
Thanks
 

shashkiranr

Active Member
Licensed User
Longtime User
Hi Agraham,

Thank you for this amazing Lib :) Is it possible to use this in Live wall paper ? Since Gifdecoder is Activity Object and it cannot be declared in Sub process global.

Is there a workaround for it. It would be great help if i can use this in a Live Wallpaper.

Kindly let me know your inputs and Suggestions.

Regards,
SK
 

Fillmore

Member
Licensed User
Longtime User
Hi agraham,

Thanks for your lib.
I've got a problem with it.
In the following app, if I check "G" and "A" and click the button "1", it works. After this, if I check "B" and click again on the button "1", it crash with this error message : " java.lang.ArrayIndexOutOfBoundsException: length=47400; index=47400 "

I don't found why...

Thanks a lot.

Fred
 

Attachments

  • gym gif.zip
    58.1 KB · Views: 237

BedDweller

Member
Licensed User
Longtime User
Trying to get this running on b4a 3.5 running api 19 (kitkat), however I'm always getting "
java.io.FileNotFoundException: clonesheep.gif " even the example program included is giving this error.
Any ideas and why this is occurring?
 

Ddancer

Member
Licensed User
Longtime User
Hi
When I try to use two animations (gif) at same time I get "java.lang.ArrayIndexOutOfBoundsException' . I used two different timers and a Frame2 var -unable to run both a same time. Independent they both work. I must be missing something (Newbe to B4A)

Sub Process_Globals
Dim Timer1 As Timer
Dim Frame As Int
Dim Timer2 As Timer
Dim FrameB As Int
Timer1.Initialize("Timer1",0)
Timer2.Initialize("Timer2",0)
End Sub

Sub Bore
gif.DisposeFrames
gif.Load(File.DirAssets, "Bore.gif")
FrameB = 0
Timer2.Interval = gif.Delay(FrameB)
imgBore.Bitmap = gif.Frame(FrameB)
Timer2.Enabled = True
gif.SaveFrame(0, File.DirRootExternal, "frame0.png", "P", 85)
gif.SaveFrame(0, File.DirRootExternal, "frame0.jpg", "J", 85)
End Sub

Sub Killer
gif.DisposeFrames
gif.Load(File.DirAssets, "Killerfish3.gif")
Frame = 0
Timer1.Interval = gif.Delay(Frame)
imgKillerFish.Bitmap = gif.Frame(Frame)
Timer1.Enabled = True
gif.SaveFrame(0, File.DirRootExternal, "frame0.png", "P", 85)
gif.SaveFrame(0, File.DirRootExternal, "frame0.jpg", "J", 85)
End Sub

Sub Timer1_Tick
Timer1.Enabled = False
Frame = Frame + 1
If Frame >= gif.FrameCount Then
Frame = 0
EndIf
Timer1.Interval = gif.Delay(Frame)
imgKillerFish.Bitmap = gif.Frame(Frame)
Timer1.Enabled = True
End Sub

Sub Timer2_Tick
Timer2.Enabled = False
FrameB = FrameB + 1
If FrameB >= gif.FrameCount Then
FrameB = 0
EndIf
Timer2.Interval = gif.Delay(FrameB)
imgBore.Bitmap = gif.Frame(FrameB)
Timer2.Enabled = True

End Sub
 

adjie

Member
Licensed User
Longtime User
It is probably related to the new virtual assets folder (you can read more about it here: http://www.basic4ppc.com/android/forum/threads/java-loading-files-from-a-library.38728/#content)

You will need to disable this feature with this line:
B4X:
#DebuggerForceStandardAssets: true
Yes! This is the answer.
I also got the same error log "FileNotFoundException".
And after puting above code, now it's running well. Thanks erel ! I've been looking for couple days cause alot of some example using images also got this error because of this.
 

Rusty

Well-Known Member
Licensed User
Longtime User
I have an animated gif with 40 images within. (46kb total size)
It is taking almost 3 seconds to load using Gif Animator lib.
I run the GifAnimator in a class and for some reason I can't make the loaded GIF file persist. Each time i initialize the class, it of course reloads everything.
Is there a way to:
a. speed up the load...it's only 46KB
b. persist the loaded GifDecoder data
c. store it somewhere it doesn't make the class refer to i.e. Main to get it (I know I can pass the GIFDEODER in as an initialization parameter)

any help will be appreciated.
Rusty
 

Roger Taylor

Member
Licensed User
Longtime User
Have you moved the jar and the xml file in the archive to your additional libraries folder?

I'm late replying to this thread but thought I'd ask a few questions about some errors I'm getting with this library. Sometimes I get an ArrayOutOfBounds error claiming that an index of 22500, etc. sometimes even 6 digits long and the B4A debugger shows a SetPixel operation just before the error occurs. I was wondering if you have updated this library to get rid of the bugs and where I can find the latest version? The error seems to be happening on pictures that have previously loaded and displayed fine with animation and I can't pinpoint what is going on but I'm using your own source example. If you don't plan on updating this library do you know if there is another one for displaying animated GIFs? Thank you.
 

Roger Taylor

Member
Licensed User
Longtime User
Cannot remember if I used the same library but here is a sample app that I have done some time ago
https://www.b4x.com/android/forum/threads/gif-file-3-x-rotating-earth.45251/

I could only find version 1.0 of the GifDecoder library and it has the same bugs that has been reported in this thread yet the author doesn't seem to have a solution? The ArrayOutOfBounds error that is generated close to the SetPixel function in his library happens sometimes, not all the time. I look at his replies and I'm convinced by the dates on the messages that the library must be dead on arrival which is very unfortunate because when it Does work it works okay. The crashes are unacceptable, though. Do you know where the library repo is? I can't find the link now. Also, do you know of any other animated GIF libraries for B4A ? Thanks.
 
Top