Re: GifDecoder module (All OS, single frame & animated gifs)
Posted: Fri Sep 04, 2015 10:46 pm
Nice, thank you for the possibility of an easy and proper GIF display in PB! 
http://www.purebasic.com
https://www.purebasic.fr/english/

Code: Select all
KillThread(*PtrAnimate\ThreadID)Code: Select all
*PtrAnimate\Quit = #True
*PtrAnimate\Target = 0Code: Select all
If IsGadget(Target)
SetGadgetState(Target, Image)
EndIf 

I didn't get such error myself but an extra check does no harm so I added the gadget check to the module code in the first post.Kwai chang caine wrote:Just i allowed myself to massacre your work by adding![]()
Code: Select all
If IsGadget(Target) SetGadgetState(Target, Image) EndIf
It's my passionYou keep amazing me with the amount of animated gifs you have


SPLENDID !!!
It's when i jump between JPG and GIF in the same imageGadget, perhaps an error of meI didn't get such error myself but an extra check does no harm so I added the gadget check to the module code in the first post.


Code: Select all
UseGIFImageDecoder()
Code: Select all
;
; ------------------------------------------------------------
;
; PureBasic - ImagePlugin GIF Viewer example file
;
; (c) Fantaisie Software
;
; Modify example by mk-soft - Upscale gif images
;
; ------------------------------------------------------------
;
; Enable the GIF decoder
UseGIFImageDecoder()
; Loading a GIF file
If LoadImage(0, #PB_Compiler_Home+"Examples/Sources/Data/PureBasicLogo.gif")
dx = ImageWidth(0)
dy = ImageHeight(0)
OpenWindow(0, 100, 100, dx, dy, "GIF viewer")
CanvasGadget(0, 0, 0, dx, dy)
; Upscale
dx = DesktopScaledX(dx)
dy = DesktopScaledY(dy)
; Add a timer to animate the GIF, starts immediately to display the first frame witout delay
AddWindowTimer(0, 0, 1)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Timer
SetImageFrame(0, Frame)
; Each GIF frame can have its own delay, so change the timer accordingly
;
RemoveWindowTimer(0, 0)
AddWindowTimer(0, 0, GetImageFrameDelay(0))
If StartDrawing(CanvasOutput(0))
DrawImage(ImageID(0), 0, 0, dx, dy)
StopDrawing()
EndIf
; Go to next frame
Frame+1
If Frame >= ImageFrameCount(0) ; Cycle back to first frame, to play in loop
Frame = 0
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
Else
Debug "Impossible to load the file: " + Filename$
EndIf