User Tools

Site Tools


displaying_20animated_20gifs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
displaying_20animated_20gifs [2018/03/31 13:19] – external edit 127.0.0.1displaying_20animated_20gifs [2024/01/05 00:22] (current) – external edit 127.0.0.1
Line 1: Line 1:
 =====Displaying animated GIFs===== =====Displaying animated GIFs=====
  
-//by Richard Russell, November 2007//\\ \\  The normal methods of displaying GIF image in a //BBC BASIC for Windows// program (using the code listed in the [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwine.html#gifjpeg|Help documentation]] or in the article [[/Displaying%20a%20JPEG%20or%20GIF%20in%20a%20picture%20box|Displaying a JPEG or GIF in a picture box]]will not display an **animated GIF** - only the first frame of the animation will be shown.\\ \\  One straightforward method of displaying an animated GIF is to use an [[/Using%20an%20ATL%20container%20control|ATL container control]]. Assuming a suitable player is available (which there will be if **Internet Explorer** is installed on the PC) this will open and display the animation continuously until the ATL window is closed. An alternative method is to use [[/Playing%20a%20media%20file%20using%20Direct%20Show|Direct Show]] which gives a greater degree of control, for example you can pause and restart the animation. However it is still rather limiting, for example there is no straightforward way of controlling the animation speed.\\ \\  When you need more control, an alternative method of displaying animated GIFs is to use the **GDI Plus** subsystem, installed as standard on **Windows XP** and **Windows Vista** and available as a redistributable file for earlier versions (**Windows 98** onwards). See the Help documentation under [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwing.html#gdiplib|Library Routines... Antialiased graphics]] for more information on GDI+.\\ \\  To use this method you must first perform some initialisation, as follows:\\ \\ +//by Richard Russell, November 2007 amended January 2022// 
 + 
 +The easiest way of displaying an **animated GIF** is to use the **imglib** libraries supplied with //BBC BASIC for Windows// and //BBC BASIC for SDL 2.0//; see the relevant [[http://bbcbasic.co.uk/bbcsdl/manual/bbcsdlg.html#imglib|documentation]].  The rest of this article describes alternative methods that may be used in //BBC BASIC for Windows// (only). 
 + 
 +One straightforward method of displaying an animated GIF is to use an [[/Using%20an%20ATL%20container%20control|ATL container control]]. Assuming a suitable player is available (which there will be if **Internet Explorer** is installed on the PC) this will open and display the animation continuously until the ATL window is closed. An alternative method is to use [[/Playing%20a%20media%20file%20using%20Direct%20Show|Direct Show]] which gives a greater degree of control, for example you can pause and restart the animation. However it is still rather limiting, for example there is no straightforward way of controlling the animation speed.\\ \\  When you need more control, an alternative method of displaying animated GIFs is to use the **GDI Plus** subsystem, installed as standard on **Windows XP** and **Windows Vista** and available as a redistributable file for earlier versions (**Windows 98** onwards). See the Help documentation under [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwing.html#gdiplib|Library Routines... Antialiased graphics]] for more information on GDI+.\\ \\  To use this method you must first perform some initialisation, as follows: 
 + 
 +<code bb4w> 
         INSTALL @lib$+"GDIPLIB"         INSTALL @lib$+"GDIPLIB"
         PROC_gdipinit         PROC_gdipinit
Line 20: Line 26:
         SYS "GetProcAddress", gdip%, "GdipDrawImageRectI"               TO `GdipDrawImageRectI`         SYS "GetProcAddress", gdip%, "GdipDrawImageRectI"               TO `GdipDrawImageRectI`
         SYS "GetProcAddress", gdip%, "GdipDisposeImage"                 TO `GdipDisposeImage`         SYS "GetProcAddress", gdip%, "GdipDisposeImage"                 TO `GdipDisposeImage`
-You may of course put this code in a procedure or library if you don't want to clutter your main program. If you need to perform your own 'cleanup' operations (on an error or when the window is closed), call your own replacement routine in the ON CLOSE and ON ERROR statements, and move the **PROC_gdipexit** there.\\ \\  Once you have carried out the initialisation you can simply display the animated GIF as follows:\\ \\ +</code> 
 + 
 +You may of course put this code in a procedure or library if you don't want to clutter your main program. If you need to perform your own 'cleanup' operations (on an error or when the window is closed), call your own replacement routine in the ON CLOSE and ON ERROR statements, and move the **PROC_gdipexit** there.\\ \\  Once you have carried out the initialisation you can simply display the animated GIF as follows: 
 + 
 +<code bb4w>
         filename$ = "C:\www\bbcwin\bbctile3.gif"         filename$ = "C:\www\bbcwin\bbctile3.gif"
         PROCanimatedgif(filename$, 500)         PROCanimatedgif(filename$, 500)
-The second parameter of **PROCanimatedgif** is the time for which you want the animation to display, in centiseconds (one-hundredths of a second).\\ \\  Once you have finished with the GDI+ subsystem (typically on exit from your program) don't forget to call **PROC_gdipexit**:\\ \\ +</code> 
 + 
 +The second parameter of **PROCanimatedgif** is the time for which you want the animation to display, in centiseconds (one-hundredths of a second).\\ \\  Once you have finished with the GDI+ subsystem (typically on exit from your program) don't forget to call **PROC_gdipexit**: 
 + 
 +<code bb4w>
         PROC_gdipexit         PROC_gdipexit
         END         END
-Here is the all-important **PROCanimatedgif** routine:\\ \\ +</code> 
 + 
 +Here is the all-important **PROCanimatedgif** routine: 
 + 
 +<code bb4w>
         DEF PROCanimatedgif(filename$, duration%)         DEF PROCanimatedgif(filename$, duration%)
         LOCAL wfile%, image%, ndims%, nframes%, frame%, psize%, xsize%, ysize%         LOCAL wfile%, image%, ndims%, nframes%, frame%, psize%, xsize%, ysize%
Line 74: Line 92:
         SYS `GdipDisposeImage`, image%         SYS `GdipDisposeImage`, image%
         ENDPROC         ENDPROC
-If the image is a 'transparent GIF' (i.e. it has a transparent background colour) the code must be modified to clear the background before each frame is displayed. One way is to alter the main display loop as shown below, which clears the background to the current Text Background Colour (as would be used by CLS):\\ \\ +</code> 
 + 
 +If the image is a 'transparent GIF' (i.e. it has a transparent background colour) the code must be modified to clear the background before each frame is displayed. One way is to alter the main display loop as shown below, which clears the background to the current Text Background Colour (as would be used by CLS): 
 + 
 +<code bb4w>
         endtime% = TIME + duration%         endtime% = TIME + duration%
         SYS "CreateSolidBrush", @vdu%?71 + &1000000 TO brush%         SYS "CreateSolidBrush", @vdu%?71 + &1000000 TO brush%
Line 88: Line 110:
         UNTIL TIME>endtime%         UNTIL TIME>endtime%
         SYS "DeleteObject", brush%         SYS "DeleteObject", brush%
 +</code>
 +
 I'm sure you can see how you could modify this code if you wanted, for example, to display the animation for a certain number of loops or a certain number of frames, rather than for a certain time. The routine centers the GIF in the window; it could easily be modified to display it in a different position or at a different size. I'm sure you can see how you could modify this code if you wanted, for example, to display the animation for a certain number of loops or a certain number of frames, rather than for a certain time. The routine centers the GIF in the window; it could easily be modified to display it in a different position or at a different size.
displaying_20animated_20gifs.1522502356.txt.gz · Last modified: 2024/01/05 00:18 (external edit)