; Module/File: Gadget_LoadedAnimationWoDecoder.pb ; Function: Add loaded gif animation to pb-ImageGadget, w/o decoder, uses pixbuf-loader - Linux (gtk2/gtk3) ; Author: Omi/Keya ; Date: Sep. 20, 2015 ; Version: 0.1 ; Target Compiler: PureBasic 5.22/5.31/5.40 ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ; Link to topic: http://www.purebasic.fr/english/viewtopic.php?f=15&t=63192 ;-------------------------------------------------------------- ;see Version w/o pixbuf-loader 'ImageGadget_AnimationFromFile.pb' EnableExplicit ImportC "" gdk_pixbuf_loader_write(*loader, *buf, count, *error) gdk_pixbuf_loader_get_animation(*loader) gdk_pixbuf_loader_new() gdk_pixbuf_loader_close(*loader, *error) gdk_pixbuf_animation_get_width(pixbuf) gdk_pixbuf_animation_get_height(pixbuf) EndImport #Win_Main= 0 Enumeration #Txt1 #ImG1 EndEnumeration Global.i gEvent, gQuit Procedure ImageAnimationGetLoaded(PicFile.s) Protected fSize= FileSize(PicFile), fId Protected loader = gdk_pixbuf_loader_new() Protected *pixbuf, *err.GError, *pMem If fSize > 0 fId= ReadFile(#PB_Any, PicFile) If fId *pMem = AllocateMemory(fSize + 16) If *pMem ReadData(fId, *pMem, fSize) CloseFile(fId) *err= 0 : gdk_pixbuf_loader_write(loader, *pMem, fSize, @*err) If *err : Debug "Error: " + PeekS(*err\message, -1, #PB_UTF8) : EndIf *err= 0 : gdk_pixbuf_loader_close(loader, @*err); Important to get the things going, else: Do you know 'Sankt Nimmerleinstag'?! If *err : Debug "Error: " + PeekS(*err\message, -1, #PB_UTF8) : EndIf If *pMem : FreeMemory(*pMem) : EndIf EndIf EndIf EndIf ProcedureReturn gdk_pixbuf_loader_get_animation(loader) EndProcedure Procedure ImageAnimationSet(Gadget, Animation) If Animation gtk_image_set_from_animation_(GadgetID(Gadget), Animation) ResizeGadget(Gadget, #PB_Ignore, #PB_Ignore, gdk_pixbuf_animation_get_width(Animation), gdk_pixbuf_animation_get_height(Animation)) EndIf EndProcedure If OpenWindow(#Win_Main, #PB_Ignore, #PB_Ignore, 500, 300, "Use loaded animation w/o ImageDecoder", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) TextGadget(#Txt1, 5, 5, 490, 45, "A PB ImageGadget with loaded decoderless gif animation ...") ImageGadget(#ImG1, 200, 110, 92, 88, #Null) ;Choose your pathes and gif animation here ... ;http://www.picgifs.com/graphics/a/3d-smileys/graphics-3d-smileys-302517.gif ImageAnimationSet(#ImG1, ImageAnimationGetLoaded("/home/charly-xubuntu/Downloads/Bilder/graphics-3d-smileys-302517.gif")) Repeat gEvent= WaitWindowEvent() If EventWindow() = #Win_Main Select gEvent Case #PB_Event_CloseWindow gQuit= #True EndSelect EndIf Until gQuit EndIf ; IDE Options = PureBasic 5.44 LTS (Linux - x86) ; CursorPosition = 7 ; Folding = - ; EnableUnicode ; EnableXP