/// <summary> /// Initializes a new instance of the <see cref="GifFrameMetaData"/> class. /// </summary> /// <param name="other">The metadata to create an instance from.</param> private GifFrameMetaData(GifFrameMetaData other) { this.ColorTableLength = other.ColorTableLength; this.FrameDelay = other.FrameDelay; this.DisposalMethod = other.DisposalMethod; }
public static ObjectAnimationUsingKeyFrames CreateFrames(GifBitmapDecoder decoder) { if (decoder == null) { return(null); } ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames(); // Read MetaData from GIF // this give us the Width and Height of the GIF GifMetaData gifData = GifMetaDataReader.GetGifMetaData(decoder); if (gifData == null) { return(null); } TimeSpan animationTime = TimeSpan.FromMilliseconds(0); BitmapSource baseFrame = null; // create a animation for every frame in GIF foreach (BitmapFrame curFrame in decoder.Frames) { // first we need to read the metadata from the frame // to know the position, width, height, delay and disposalmethod GifFrameMetaData frameMetaData = GifMetaDataReader.GetGifFrameMetaData(curFrame); if (frameMetaData != null) { // Create a "image" from the current frame BitmapSource CurCreatedFrame = GifImageFrameCreator.CreateFrame( new System.Drawing.Size(gifData.Width, gifData.Height), curFrame, frameMetaData, baseFrame); // add the frame to the animaton animation.KeyFrames.Add(new DiscreteObjectKeyFrame() { KeyTime = animationTime, Value = CurCreatedFrame }); // Check the disposal method switch (frameMetaData.DisposalMethod) { case GifFrameDisposalMethod.None: break; case GifFrameDisposalMethod.DoNotDispose: baseFrame = CurCreatedFrame; break; case GifFrameDisposalMethod.RestoreBackground: baseFrame = GifImageFrameCreator.RestoreBackground(new System.Drawing.Size(gifData.Width, gifData.Height), curFrame, frameMetaData); break; case GifFrameDisposalMethod.RestorePrevious: break; default: break; } // increse the timeline with the delay of the frame animationTime += frameMetaData.Delay; } } animation.Duration = animationTime; return(animation); }