Jun 2, 2020 Replies: 61 I was missing a cross platform, animated gif view, so created one. Usage is simple: Add with the visual designer and call SetGif to set the gif file. The B4i implementation depends on FLAnimatedImage open source project: https://github.com/Flipboard/FLAnimatedImage The B4A implementation is based on this open source project: https://github.com/koral--/android-gif-drawable The two dependent aars are attached. Copy them to B4A additional libraries folder. Updates: 1.20 - Change dependency declaration to be compatible with B4i v10+ 1.15 - Updated the B4A dependencies to fix a compatibility issue with targetSdkVersion 35. 1.12 - SetGif2 - Allows loading an animated gif from an array of bytes. 1.11 - GIF image ratio is preserved. 1.10 - New B4A implementation based on Android GIF Drawable. It provides better performance. Note that the Activity_Resume method has been removed. Don't miss the B4A-Dependencies zip file. Attachments GifExample.zip GifExample.zip 256.4 KB · Views: 740 B4A-Dependencies.zip B4A-Dependencies.zip 165.3 KB · Views: 970 B4XGifView.b4xlib B4XGifView.b4xlib 1.5 KB · Views: 965 Last edited: Nov 19, 2025 Click to expand...
I was missing a cross platform, animated gif view, so created one. Usage is simple: Add with the visual designer and call SetGif to set the gif file. The B4i implementation depends on FLAnimatedImage open source project: https://github.com/Flipboard/FLAnimatedImage The B4A implementation is based on this open source project: https://github.com/koral--/android-gif-drawable The two dependent aars are attached. Copy them to B4A additional libraries folder. Updates: 1.20 - Change dependency declaration to be compatible with B4i v10+ 1.15 - Updated the B4A dependencies to fix a compatibility issue with targetSdkVersion 35. 1.12 - SetGif2 - Allows loading an animated gif from an array of bytes. 1.11 - GIF image ratio is preserved. 1.10 - New B4A implementation based on Android GIF Drawable. It provides better performance. Note that the Activity_Resume method has been removed. Don't miss the B4A-Dependencies zip file.
Unobtainius Active Member Licensed User Longtime User Jun 3, 2020 #2 Thanks Erel. I think I tried displaying animated gifs via the webview recently but I may well have given up. So a thumbs up from me.
Thanks Erel. I think I tried displaying animated gifs via the webview recently but I may well have given up. So a thumbs up from me.
C CaptKronos Active Member Licensed User Longtime User Jun 7, 2020 #3 Hi Erel, I'm getting memory problems if a reasonably large (~1mb) gif is loaded more than once e.g. from rotating the phone running your GifViewExample. B4X: Copy b4xgifview_v6 (java line: 118) java.lang.OutOfMemoryError: Failed to allocate a 1638412 byte allocation with 1032504 free bytes and 1008KB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:904) at android.graphics.Bitmap.createBitmap(Bitmap.java:928) at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.SetPixels(GifDecoder.java:298) I have managed to fix the problem by adding to B4XGifView.b4xlib the sub: B4X: Copy Public Sub ClearBitmaps bitmaps.clear End Sub and calling ClearBitmaps before B4XGifView1.SetGif or in Activity_Pause.
Hi Erel, I'm getting memory problems if a reasonably large (~1mb) gif is loaded more than once e.g. from rotating the phone running your GifViewExample. B4X: Copy b4xgifview_v6 (java line: 118) java.lang.OutOfMemoryError: Failed to allocate a 1638412 byte allocation with 1032504 free bytes and 1008KB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:904) at android.graphics.Bitmap.createBitmap(Bitmap.java:928) at anywheresoftware.b4a.agraham.gifdecoder.GifDecoder.SetPixels(GifDecoder.java:298) I have managed to fix the problem by adding to B4XGifView.b4xlib the sub: B4X: Copy Public Sub ClearBitmaps bitmaps.clear End Sub and calling ClearBitmaps before B4XGifView1.SetGif or in Activity_Pause.
Erel B4X founder Staff member Licensed User Longtime User Jun 7, 2020 #4 The bitmaps list is cleared together with the view when the activity is destroyed. Have you called SetGif on the same GifView multiple times?
The bitmaps list is cleared together with the view when the activity is destroyed. Have you called SetGif on the same GifView multiple times?
C CaptKronos Active Member Licensed User Longtime User Jun 7, 2020 #5 I haven't changed your GifViewExample apart from loading a larger gif. B4X: Copy B4XGifView1.SetGif(File.DirAssets, "giphy.gif") Then on rotating the phone I get the memory error. Also, for an artificial example, this gives the memory error: B4X: Copy B4XGifView1.SetGif(File.DirAssets, "giphy.gif") B4XGifView1.SetGif(File.DirAssets, "giphy.gif") But this is fine: B4X: Copy B4XGifView1.SetGif(File.DirAssets, "giphy.gif") B4XGifView1.ClearBitmaps B4XGifView1.SetGif(File.DirAssets, "giphy.gif")
I haven't changed your GifViewExample apart from loading a larger gif. B4X: Copy B4XGifView1.SetGif(File.DirAssets, "giphy.gif") Then on rotating the phone I get the memory error. Also, for an artificial example, this gives the memory error: B4X: Copy B4XGifView1.SetGif(File.DirAssets, "giphy.gif") B4XGifView1.SetGif(File.DirAssets, "giphy.gif") But this is fine: B4X: Copy B4XGifView1.SetGif(File.DirAssets, "giphy.gif") B4XGifView1.ClearBitmaps B4XGifView1.SetGif(File.DirAssets, "giphy.gif")
Erel B4X founder Staff member Licensed User Longtime User Jun 8, 2020 #6 CaptKronos said: Then on rotating the phone I get the memory error. Click to expand... I don't think that clearing the bitmaps list will help in this case as the class instance is released anyway. Have you tested it in release mode?
CaptKronos said: Then on rotating the phone I get the memory error. Click to expand... I don't think that clearing the bitmaps list will help in this case as the class instance is released anyway. Have you tested it in release mode?
C CaptKronos Active Member Licensed User Longtime User Jun 8, 2020 #7 Yep, the same problem in release mode.
C CaptKronos Active Member Licensed User Longtime User Jun 8, 2020 #8 What I have just realised is that I under-reported the filesize of the gif. It was a 8mb (not 1mb) gif that was causing the problem on a YotaPhone 2 (2 GB RAM). On a Samsung S3, a 1mb gif causes the problem. On a Samsung S8, the 8mb gif is fine. Do you think it could be just the way I call ClearBitmaps before the class is released, gives the garbage handling more time to run?
What I have just realised is that I under-reported the filesize of the gif. It was a 8mb (not 1mb) gif that was causing the problem on a YotaPhone 2 (2 GB RAM). On a Samsung S3, a 1mb gif causes the problem. On a Samsung S8, the 8mb gif is fine. Do you think it could be just the way I call ClearBitmaps before the class is released, gives the garbage handling more time to run?
Erel B4X founder Staff member Licensed User Longtime User Jun 8, 2020 #9 CaptKronos said: Do you think it could be just the way I call ClearBitmaps before the class is released, gives the garbage handling more time to run? Click to expand... Might be.
CaptKronos said: Do you think it could be just the way I call ClearBitmaps before the class is released, gives the garbage handling more time to run? Click to expand... Might be.
Erel B4X founder Staff member Licensed User Longtime User Jun 28, 2020 #10 1.10 - New B4A implementation based on Android GIF Drawable. It provides better performance. Note that the Activity_Resume method has been removed. Don't miss the B4A-Dependencies zip file.
1.10 - New B4A implementation based on Android GIF Drawable. It provides better performance. Note that the Activity_Resume method has been removed. Don't miss the B4A-Dependencies zip file.
C CaptKronos Active Member Licensed User Longtime User Jun 29, 2020 #11 With the new version I'm no longer seeing the memory problem. Also, with the first version I was seeing some display corruption when showing large animated gifs. This is no longer the case. It seems perfect now.
With the new version I'm no longer seeing the memory problem. Also, with the first version I was seeing some display corruption when showing large animated gifs. This is no longer the case. It seems perfect now.
Erel B4X founder Staff member Licensed User Longtime User Jul 12, 2020 #12 v1.11 - GIF image ratio is preserved.
AnandGupta Expert Licensed User Longtime User Jul 21, 2020 #13 Erel said: v1.11 - GIF image ratio is preserved. Click to expand... May be it was bug earlier, but I was using it show in full activity area, in any phone size, gvGIF.SetGif(File.DirAssets, "clouds.gif") Now the ratio is preserved and does not look good. How to make it full screen like before without restoring to older library ? Regards, Anand
Erel said: v1.11 - GIF image ratio is preserved. Click to expand... May be it was bug earlier, but I was using it show in full activity area, in any phone size, gvGIF.SetGif(File.DirAssets, "clouds.gif") Now the ratio is preserved and does not look good. How to make it full screen like before without restoring to older library ? Regards, Anand
Unobtainius Active Member Licensed User Longtime User Jul 22, 2020 #14 preserve aspect ratio is normally a toggle Is the source available?
Erel B4X founder Staff member Licensed User Longtime User Jul 22, 2020 #15 Unobtainius said: Is the source available? Click to expand... The source is inside the b4xlib (zip) file. AnandGupta said: Now the ratio is preserved and does not look good. Click to expand... In most cases images look better when the ratio is preserved. You will need to use the source code and remove the call to ResizeBasedOnImage.
Unobtainius said: Is the source available? Click to expand... The source is inside the b4xlib (zip) file. AnandGupta said: Now the ratio is preserved and does not look good. Click to expand... In most cases images look better when the ratio is preserved. You will need to use the source code and remove the call to ResizeBasedOnImage.
AnandGupta Expert Licensed User Longtime User Jul 22, 2020 #16 Erel said: In most cases images look better when the ratio is preserved. Click to expand... Yes, but here I was using the bug to show full screen, something which looks good in any shape clouds Erel said: You will need to use the source code and remove the call to ResizeBasedOnImage. Click to expand... Ahh..the dreaded path.. I know the source is there, but I am still a novice as far as changing library source is concerned. Actually I am afraid as I may dismantle something else. Will give it a try. Any hint how to add an option so that the library produces both results ? Regards, Anand
Erel said: In most cases images look better when the ratio is preserved. Click to expand... Yes, but here I was using the bug to show full screen, something which looks good in any shape clouds Erel said: You will need to use the source code and remove the call to ResizeBasedOnImage. Click to expand... Ahh..the dreaded path.. I know the source is there, but I am still a novice as far as changing library source is concerned. Actually I am afraid as I may dismantle something else. Will give it a try. Any hint how to add an option so that the library produces both results ? Regards, Anand
M mohd_farez Member Licensed User Aug 2, 2020 #18 mohd_farez said: how to hide B4XGifView ? Click to expand... solved using B4XView
Erel B4X founder Staff member Licensed User Longtime User Aug 2, 2020 #19 All custom views expose the base panel that holds them (mBase). You can use it to hide or move the view.
All custom views expose the base panel that holds them (mBase). You can use it to hide or move the view.
M mohd_farez Member Licensed User Aug 2, 2020 #20 Erel said: All custom views expose the base panel that holds them (mBase). You can use it to hide or move the view. Click to expand... ok , thank u Erel
Erel said: All custom views expose the base panel that holds them (mBase). You can use it to hide or move the view. Click to expand... ok , thank u Erel