This is, of course, Richard's routine - I'm not clever enough to do all that by myself - but it shows the various installs and initialisations which it is only too easy to overlook (and which the original questioner did overlook!) The first six lines might be better placed in a PROCinit somewhere.
Code: Select all
INSTALL @lib$+"GDIPLIB"
INSTALL @lib$+"IMGLIB"
PROC_gdipinit
PROC_imgInit
PROCinitgdiplus
DIMrc{l%,t%,r%,b%}
file$="H:\Trips\Cornwall\Man_engine_animation.gif 2"
PROCanimatedgif(file$)
END
:
REM Displays animated gifs
DEFPROCanimatedgif(filename$):CLS
LOCALwfile%,image%,ndims%,nframes%,frame%,psize%,xsize%,ysize%
LOCALxpos%,ypos%,endtime%,DimensionIDs{},PropItem%,delay%
REM Check if a scale has been specified
i%=INSTR(filename$," "):ascale%=1
IFi%>0ascale%=VALMID$(filename$,i%+1):filename$=LEFT$(filename$,i%-1)
DIMwfile%LOCALLEN(filename$)*2+1
SYS"MultiByteToWideChar",0,0,filename$,-1,wfile%,LEN(filename$)+1
SYS`GdipLoadImageFromFile`,wfile%,^image%
IFimage%=0 ERROR 100,"File not found"
SYS`GdipImageGetFrameDimensionsCount`,image%,^ndims%
DIMDimensionIDs{(ndims%) a%,b%,c%,d%}
SYS`GdipImageGetFrameDimensionsList`,image%,DimensionIDs{(0)},ndims%
SYS`GdipImageGetFrameCount`,image%,DimensionIDs{(0)},^nframes%
PropertyTagFrameDelay%=&5100
SYS`GdipGetPropertyItemSize`,image%,PropertyTagFrameDelay%,^psize%
DIMPropItem%LOCALpsize%
SYS`GdipGetPropertyItem`,image%,PropertyTagFrameDelay%,psize%,PropItem%
SYS`GdipGetImageWidth`,image%,^xsize%
SYS`GdipGetImageHeight`,image%,^ysize%
SYS"GetClientRect",@hwnd%,rc{}
tmp%=FN_gdipsetdc(@memhdc%)
xsize%=xsize%*ascale%:ysize%=ysize%*ascale%
REM Scale the picture to fit the window
IFxsize%>rc.r%ysize%*=rc.r%/xsize%:xsize%=rc.r%
IFysize%>rc.b%xsize%*=rc.b%/ysize%:ysize%=rc.b%
xpos%=(rc.r%-xsize%)/2
ypos%=(rc.b%-ysize%)/2
rc.l%=xpos%:rc.r%=xpos%+xsize%
rc.t%=ypos%:rc.b%=ypos%+ysize%
REPEAT
SYS`GdipImageSelectActiveFrame`,image%,DimensionIDs{(0)},frame%
SYS`GdipDrawImageRectI`,FN_gdipg,image%,xpos%,ypos%,xsize%,ysize%
SYS"InvalidateRect",@hwnd%,rc{},0
delay%=PropItem%!(16+4*frame%)
IFdelay%g%=INKEY(delay%)ELSEg%=INKEY(8)
frame%=(frame%+1)MODnframes%
UNTILg%=136ORg%=137
SYS`GdipDisposeImage`,image%
ENDPROC
:
REM For animated gifs
DEFPROCinitgdiplus
SYS"LoadLibrary","GDIPLUS.DLL"TOL@imglib%
SYS "GetProcAddress",L@imglib%,"GdipImageGetFrameDimensionsCount" TO`GdipImageGetFrameDimensionsCount`
SYS "GetProcAddress",L@imglib%,"GdipImageGetFrameDimensionsList" TO`GdipImageGetFrameDimensionsList`
SYS "GetProcAddress",L@imglib%,"GdipImageGetFrameCount" TO`GdipImageGetFrameCount`
SYS "GetProcAddress",L@imglib%,"GdipImageSelectActiveFrame" TO`GdipImageSelectActiveFrame`
SYS "GetProcAddress",L@imglib%,"GdipGetPropertyItemSize" TO`GdipGetPropertyItemSize`
SYS "GetProcAddress",L@imglib%,"GdipGetPropertyItem" TO`GdipGetPropertyItem`
SYS "GetProcAddress",L@imglib%,"GdipDrawImageRectI" TO`GdipDrawImageRectI`
lGDIP%=0
ENDPROC
Note that it is sufficient to specify the picture name and path:
file$="F:\picture.gif"
The number afterwards is optional but specifies a scale, thus this gives you a picture double size.
file$="F:\picture.gif 2"