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;