Link: http://user.qzone.qq.com/463450970/blog/1220702709
For GIF animated images, use cimagedecoder to decode and display them. There are some instructions on the Internet. Here is some of the code I have debugged. You can play it. It's your own note.
Definition of related variables in the header file:
Tint itype;
Cimagedecoder * idecoder;
Cfbsbitmap * ibitmap;
Cfbsbitmap * ibitmapmark; // mask bitmap
Cgiftimer * igiftimer;
Ttimeintervalmicroseconds32 idisplaytimer;
Tframeinfo iframeinfo;
Tint icurframe;
Tint iframecount;
Main Code of GIF animation playback in the source file:
Void cimage: startgif ()
{
Cancel ();
Delete idecoder;
Idecoder = NULL;
Delete ibitmap;
Ibitmap = NULL;
Delete ibitmapmark;
Ibitmapmark = NULL;
This-> idecoder = cimagedecoder: filenewl (ceikonenv: static ()-> fssession (), ifilename, cimagedecoder: eallowgeneratedmask );
If (iframecount = 0)
Iframecount = This-> idecoder-> framecount (); // get the frames of GIF animated images
If (icurframe = iframecount )//After the last frame, the first frame is played again, so it is set to zero.
Icurframe = 0;
Iframeinfo = idecoder-> frameinfo (icurframe );//Get frame information
Ibitmap = new (eleave) cfbsbitmap ();
Ibitmap-> Create (iframeinfo. ioverallsizeinpixels, iframeinfo. iframedisplaymode); // note the difference between bitmap creation and mask bitmap creation.
Ibitmapmark = new (eleave) cfbsbitmap ();
Ibitmapmark-> Create (iframeinfo. ioverallsizeinpixels, egray256); // For the parameters here, the SDK provides instructions and will be used in the next statement code.
Idecoder-> convert (& istatus, * ibitmap, * ibitmapmark, icurframe); // view the SDK
Istate = edecoding;
Setactive ();
}
Void cimage: runl ()
{
If (istatus. INT () = kerrnone)
{
Istate = edecodover;
This-> iobserver. imagedecodeover (istatus. INT (); // draw an image using the observer notification
If (itype = egif)
{
Igiftimer-> startl (ttimeintervalmicroseconds32 (iframeinfo. idelay. int64 ()));//Start the timer here. Note that the latency is obtained from the frame information. I think it is best not to set the interval by yourself.
}
}
Else
User: Leave (istatus. INT ());
}
Void cimage: gifframeconverstate ()//This is a scheduled observer function, that is, the implementation of the latency settings in runl above.
{
Icurframe ++ ;//Decodes and plays the next frame.
Startgif ();
}
Void cgifappview: Draw (const trect &/* arect */) const
{
// Get the standard graphics context
Cwindowgc & GC = systemgc ();
// Gets the control's extent
Trect drawrect (rect ());
// Clears the screen
// GC. Clear (drawrect); // do not clear the screen here
GC. bitbltmasked (iimage-> getcurframetl (), iimage-> getbitmap (), rect (),
Iimage-> getbitmapmark (), efalse );
}
The above is the main functional code. It should be clear that we hope that the passing boss will not joke.