Live Chat Icon For mobile
Live Chat Icon

How can I read individual frames from an animated image?

Platform: WinForms| Category: Bitmaps and Images

GDI+ has direct support for reading and outputting animated images.

To get at the individual frames, you can use the image’s FrameDimensionList, and then call SelectActiveFrame, by passing in the dimension and the zero based frame index.

First, create a new FrameDimension object:


FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(myImage.FrameDimensionsList[0]);

Once you have the dimension, you can get the frame count:


int frameCount = myImage.GetFrameCount(dimension);

Now, that you know the frame count of the image, you can call SelectActiveFrame by passing in the dimension and the frame index (zero based).


myImage.SelectActiveFrame(dimension,1);

If the image is being viewed at runtime, then the call to SelectActiveFrame will set the current frame, and then begin to loop through again (unless it is a jpeg image). The attached sample works around this by saving the image to a MemoryStream for display – thereby capturing the one frame that is chosen.

Sample Application w/Source Code C# or VB

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.