In this example:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; listbox1: tlistbox; opendialog1: topendialog; Procedure upload (Sender: tobject); Procedure formdestroy (Sender: tobject); Procedure button1click (Sender: tobject); Procedure upload (Sender: tobject ); procedure listbox1click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses gdipobj, gdipapi; var IMG: tgpimage; gifframe, gifframecount: word; Procedure tform1.formcreate (Sender: tobject); begin opendialog1.filter: = 'gif file | *. GIF '; IMG: = tgpimage. create; end; Procedure tform1.formdestroy (Sender: tobject); begin IMG. free; end; Procedure tform1.button1click (Sender: tobject); var dimensionscount: integer; dimensionsids: pguid; I: integer; Type arrdimensions = array of tguid; begin if not %then exit; IMG. free; IMG: = tgpimage. create (opendialog1.filename); {retrieve total GIF frames} dimensionscount: = IMG. getframedimensionscount; getmem (dimensionsids, dimensionscount * sizeof (tguid); IMG. getframedimensionslist (dimensionsids, dimensionscount); gifframecount: = IMG. getframecount (arrdimensions (dimensionsids) [0]); freemem (dimensionsids); text: = format ('total % d frames ', [gifframecount]); {display frame list} listbox1.clear; for I: = 1 to gifframecount do listbox1.items. add (format ('frame % d', [I]); repaint; end; Procedure tform1.formpaint (Sender: tobject); var G: tgpgraphics; begin G: = tgpgraphics. create (canvas. handle); G. drawimage (IMG, listbox1.width + 10, 10, IMG. getwidth, IMG. getheight); G. free; end; Procedure tform1.listbox1click (Sender: tobject); begin gifframe: = listbox1.itemindex; IMG. selectactiveframe (framedimensiontime, gifframe); repaint; end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 206 clientwidth = 339 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false oncreate = formcreate ondestroy = formdestroy onpaint = formpaint pixelsperinch = 96 textheight = 13 object listbox1: tlistbox left = 0 Top = 0 width = 89 Height = 206 align = alleft itemheight = 13 taborder = 0 onclick = listbox1click end object button1: tbutton left = 256 Top = 173 width = 75 Height = 25 caption = 'button1' taborder = 1 onclick = button1click end object opendialog1: topendialog left = 160 Top = 104 endend