[SOLVED] Display an animated .GIF

Just starting out? Need help? Post your questions and find answers here.
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

[SOLVED] Display an animated .GIF

Post by StarWarsFan »

I do not quite remember where I got this code from, but until now I have been using this:

Code: Select all

FileName$="FM.gif"
Buffer$=Space(512) 
GetFullPathName_(FileName$,Len(Buffer$),@Buffer$,@FilePart) 
animgif$ = PeekS(@Buffer$) 

OpenWindow(0,200,200,550,400,"",#PB_Window_SystemMenu) 
url$="about:<html><body scroll='no' leftmargin='0' topmargin='0'><img src='"+animgif$+"'></img></body></html>"
WebGadget(0,20,20,500,363,url$)
Repeat : ev=WaitWindowEvent() : Until ev=#PB_Event_CloseWindow

It works and displays the file.
But: a file that is on disk

How do I get this done using a file that is included in a DATASECTION ?

Any constructive help greatly appreciated. TIA!

// Edit: Code tags added. (Kiffi)
Last edited by StarWarsFan on Thu Jun 04, 2020 11:58 am, edited 1 time in total.
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: Display an animated .GIF

Post by Marc56us »

That won't answer your question, maybe you want to use the webgadget, but if not, PB can now display animated GIF as image, since 5.60 with UseGIFImageDecoder()
So the image can be stored in Datasection like any other image.

Example

:wink:
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Display an animated .GIF

Post by Josh »

Such requests should not be answered at all. If StarWarsFan is not able to ask a question properly after 41 posts, this shows only a low appreciation of the other forum participants:

"I don't click too much, I am much too good for that. Let the other idiots here on the forum take care of it, so they can read my question."
sorry for my bad english
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Display an animated .GIF

Post by netmaestro »

This'll work: https://www.purebasic.fr/english/viewto ... 12&t=57656

Just include the AnimationGadget code as a .pbi and there's a (much smaller) code example following demonstrating the usage.
BERESHEIT
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: Display an animated .GIF

Post by StarWarsFan »

Marc56us wrote:That won't answer your question
@Marc56us:
Correct, it does not answer my question. My question is about an animated .GIF. Your comment is about a standard .GIF

Josh wrote:Such requests should not be answered at all. If StarWarsFan is not able to ask a question properly...
@Josh:
What is wrong with my request? Why do YOU not consider proper?

netmaestro wrote:This'll work: https://www.purebasic.fr/english/viewto ... 12&t=57656
Just include the AnimationGadget code as a .pbi and there's a (much smaller) code example following demonstrating the usage.
@netmaestro:
Many thanks. I am going to try that out in a minute!
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: Display an animated .GIF

Post by StarWarsFan »

Update:

Thread can be marked [SOLVED].

@netmaestro:
Many thanks, that works not only as expected, but "like a charm" ;)
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Display an animated .GIF

Post by Josh »

StarWarsFan wrote:@Josh:
What is wrong with my request? Why do YOU not consider proper?
Your first post was without code tags. Probably added by a mod.
sorry for my bad english
User avatar
Kiffi
Addict
Addict
Posts: 1357
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Display an animated .GIF

Post by Kiffi »

Josh wrote:Your first post was without code tags. Probably added by a mod.
yes, unfortunately I didn't write that down. I did now.
Hygge
BarryG
Addict
Addict
Posts: 3324
Joined: Thu Apr 18, 2019 8:17 am

Re: Display an animated .GIF

Post by BarryG »

Seen a few examples above, but here's my contribution for an embedded AnimGIF.

Code: Select all

UseGIFImageDecoder()

If OpenWindow(0, 100, 100, 500, 300, "AnimGIF")

  speed = 100 ; Milliseconds.
  AddWindowTimer(0, speed, speed)
  
  CatchImage(0, ?AnimGIF)
  frames = ImageFrameCount(0)
  animframe = -1
  
  ImageGadget(0, 10, 10, 480, 280, 0)
  
  Repeat

    Event = WaitWindowEvent()

    If Event = #PB_Event_Timer
      animframe + 1
      If animframe = frames
        animframe = 0
      EndIf
      SetImageFrame(0, animframe)
      SetGadgetState(0, ImageID(0))
    EndIf

  Until Event = #PB_Event_CloseWindow
  
EndIf

End

DataSection
  AnimGIF: : IncludeBinary "C:\Animation.gif"
EndDataSection
Last edited by BarryG on Mon May 04, 2020 12:00 pm, edited 1 time in total.
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: Display an animated .GIF

Post by Marc56us »

My question is about an animated .GIF. Your comment is about a standard .GIF
... PB can now display animated GIF as image, since 5.60 ...
So you didn't try the given code I quoted (given by Fred himself). PB can display animated GIF.
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: Display an animated .GIF

Post by Thorsten1867 »

You can use "ImageExModule"

Gesendet von meinem Aquaris X2 mit Tapatalk
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
Post Reply