Learn more about GDI + [103]: tgpimage (23)-extract each frame of GIF Animation

Source: Internet
Author: User
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

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.