Gdiplus reads and displays GIF

Source: Internet
Author: User

The bitmap provided by gdiplus supports reading and displaying GIF files.

However, for some GIF images, the interval between frames may be 0. Therefore, the default interval is 100 ms in this case. I don't know if I am not correct. If you have any suggestions, please feel free to contact us! (The interval between frames is also 0 in the gimp test. I think there should be a default value. The Ms effect is acceptable and can be borrowed for the moment)

# Define um_timer_gifnextframe (wm_user + 0x01) // message for timer <br/> int iphotoframecurrent = 0; <br/> int iphotoframeindex; <br/> guid * pphotoframedimensionids = NULL; <br/> propertyitem * pphotoframeitem = NULL; <br/> void gifinit (Bitmap * psrc) <br/>{< br/> iphotoframeindex = psrc-> getframedimensionscount (); <br/> pphotoframedimensionids = (guid *) New guid [iphotoframeindex]; <br/> psrc-> getframedimensions List (pphotoframedimensionids, iphotoframeindex); <br/> wchar strguid [64] = {0}; <br/> stringfromguid2 (pphotoframedimensionids [0], strguid, 64 ); <br/> int iphotoframecount = psrc-> getframecount (& pphotoframedimensionids [0]); <br/> If (iphotoframecount = 1) // not dynamic GIF, only one frame <br/>{< br/> return; <br/>}< br/> uint totalbuffer = psrc-> getpropertyitemsize (propertytagframedelay); <br/> pphotoframeit Em = (propertyitem *) malloc (totalbuffer); <br/> psrc-> getpropertyitem (propertytagframedelay, totalbuffer, pphotoframeitem); <br/> iphotoframecurrent = 0; <br/> guid = framedimensiontime; <br/> psrc-> selectactiveframe (& guid, iphotoframecurrent ); // get current frame <br/> int delay = (uint *) pphotoframeitem [0]. value) [iphotoframecurrent]; <br/> If (0 = delay) // No Delay Time, use default 100 ms <br/>{< br/> Delay = 100; <br/>}< br/> settimer (um_timer_gifnextframe, delay, null); <br/> ++ iphotoframecurrent; <br/> g_bgifstoped = false; <br/>}< br/> void ontimer (uint_ptr nidevent) <br/>{< br/> If (um_timer_gifnextframe = nidevent) <br/>{< br/> killtimer (nidevent); <br/> If (iphotoframecount = 1) <br/>{< br/> return; <br/>}< br/> guid = framedimensiontime; <br/> psrc-> selectactiveframe (& guid, iphotoframecurren T); <br/> int delay = (uint *) pphotoframeitem [0]. value) [iphotoframecurrent] * 10; // I also want to know why Mul 10 here ?? <Br/> If (0 = delay) <br/> delay = 100; <br/> settimer (um_timer_gifnextframe, delay, null ); <br/> iphotoframecurrent = (++ iphotoframecurrent) % iphotoframecount; <br/>}< br/> free (pphotoframeitem); // free after used! <Br/> Delete [] pphotoframedimensio <br/>

 

For specific code, see.

The main idea is to read the GIF file, use psrc-> getframecount () to get the number of GIF frames, and use psrc-> selectactiveframe () to set the current image to the X frame in the GIF, finally, the time delay and the current frame update are realized through sleep () and timer.

 

In the above Code:

Bitmap * psrc =: New Bitmap (filename );

Also

: Delete psrc;

 

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.