Http://www.cppblog.com/TechLab/articles/862.html
A multi-page image contains multiple graphic pages. Each page can be seen as an image frame. These image frames form an animation through continuous display. For exampleGIFFile.
GDI + Of Image Object provides direct GIF , TIF File format. Call Image Object member functions Getframedimensionscount You can get Image Object Dimension Number. Each Dimension Through Guid Mark. Function Getframedimensionslist Returns all Dimension Of Guid Value. First Guid Value stored in function parameters Pdimensionsids Array Index 0 . Getframecount You can obtain Dimension Number Frame .Simple ExampleCode:
Image * image = new image (L "multiframe.gif ");
Uint COUNT = 0;
Count = image-> getframedimensionscount ();
Guid * pdimensionids = (guid *) New guid [count];
Image-> getframedimensionslist (pdimensionids, count );
Wchar strguid [39];
Stringfromguid2 (pdimensionids [0], strguid, 39 );
Uint framecount = image-> getframecount (& pdimensionids [0]);
Delete [] pdimensionids;
Not all GIF Files contain multiple frames, so we are GIF You can use the above Code Framecount To determine this GIF Whether the file has multiple frames.
After you confirm that there are multiple frames of the image, you need to obtain the display interval of each frame of the image. GDI + Of Image Object provides Getpropertyitem Obtains the attributes of an image. Getpropertyitem The function requires the user to pass the returned data buffer and size. Therefore, use Getpropertyitemsize Obtain the required buffer size, allocate space, and then obtain the attribute data.
// Propertytagframedelay Yes GDI + Pre-defined Gig Attribute ID Value, indicating the delay time of the tag frame data.
Int size = getpropertysize (propertytagframedelay );
Propertyitem * pitem = NULL;
Pitem = (propertyitem *) malloc (size );
Image-> getpropertyitem (propertytagframedelay, size, pitem );
In this way Propertytagframedelay Property-related data is retrieved Pitem . Then Pitem In the access structure Value . The interval between two frames is not necessarily the same. Therefore, you need to obtain the index value of the currently displayed frame image. Last call Image Object Drawimage The function draws an image of each frame. The simple code is as follows:
IntFcount = 0;
// Guid Value display GIF Is Framedimensiontime , Display TIF Is Framedimensionpage
GuidGuid = framedimensiontime;
While (thue)
{
Graphics GH (HDC); // HDC Is an external drawing DC
Gh. drawimage (image, 0, 0, image-> getwidth (), image-> getheight ());
// Reset the current active data frame
Image-> selectactiveframe (& guid, fcount ++ );
If (fcount = framecount) // framecount Yes Getframecount Return Value
Fcount = 0;// If the last frame of data starts again
// Calculate the delay time of this frame.
Long lpause = (long *) pitem-> value) [fcount] * 10;
Sleep (lpause );// This is simple to use. Sleep
}