Gdiplus Read and display Gif

Source: Internet
Author: User

Gdiplus provides bitmap support for reading and displaying GIF files.

However, for some GIF pictures may appear between the frame interval of 0, for this reason, the default interval of 100ms in this case, do not know whether I did not find the right, there are suggestions welcome feedback. (Test in GIMP also will appear between the frame interval of 0, I think there should be a default value bar, 100ms effect can be accepted, for the moment borrowed)

#define UM_TIMER_GIFNEXTFRAME (WM_USER+0X01)//message for TIMER int iphotoframecurrent = 0; int iphotoframeindex; guid* pphotoframedimensionids = NULL; propertyitem* Pphotoframeitem = NULL; void Gifinit (bitmap* psrc) {iphotoframeindex = Psrc->getframedimensionscount (); pphotoframedimensionids = (GUID*) New Guid[iphotoframeindex]; Psrc->getframedimensionslist (Pphotoframedimensionids, Iphotoframeindex); WCHAR strguid[64] = {0}; StringFromGUID2 (Pphotoframedimensionids[0], strGUID, 64); int Iphotoframecount=psrc->getframecount (&pphotoframedimensionids[0]); if (iphotoframecount==1)//not dynamic GIF, only one frame {return;} UINT Totalbuffer = psrc->getpropertyitemsize (Propertytagframedelay); Pphotoframeitem = (propertyitem*) malloc (Totalbuffer); Psrc->getpropertyitem (Propertytagframedelay,totalbuffer,pphotoframeitem); iphotoframecurrent = 0; GUID guid = Framedimensiontime; Psrc->selectactiveframe (&guid,iphotoframecurrent); Get-current frame int delay = (UINT*) (Pphotoframeitem[0].value) [iphotoframecurrent]; if (0==delay)//No delay time, use default 100ms {delay = 100;} SetTimer (um_timer_gifnextframe, delay, NULL); + + iphotoframecurrent; g_bgifstoped = FALSE; } void OnTimer (Uint_ptr nidevent) {if (Um_timer_gifnextframe = = nidevent) {KillTimer (nidevent); if (iphotoframecount==1) {return;} GUID guid = Framedimensiontime; Psrc->selectactiveframe (&guid,iphotoframecurrent); int delay = ((uint*) pphotoframeitem[0].value) [iphotoframecurrent]*10; I also want to know why Mul?? if (0==delay) delay = 100; SetTimer (um_timer_gifnextframe, delay, NULL); Iphotoframecurrent = (++iphotoframecurrent)% Iphotoframecount; } free (Pphotoframeitem); Free after used! Delete [] Pphotoframedimensio

See the specific code.

The main idea is to read the GIF file, through Psrc->getframecount () to get the number of frames in GIF, through the Psrc->selectactiveframe () to set the current picture as the X frame in GIF, and finally through sleep () and Timer () to implement the time delay and current frame update.

In the preceding code:

bitmap* PSRC =:: New Bitmap (filename);

The same last need

::d elete 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.