/// <summary> /// Saves the current image to the specified file path. /// </summary> /// <param name="path">The path to save the image to.</param> /// <param name="image">The /// <see cref="T:System.Drawing.Image" /> to save.</param> /// <returns> /// The <see cref="T:System.Drawing.Image" />. /// </returns> public override Image Save(string path, Image image) { if (!FormatUtilities.IsAnimated(image)) { image = this.Quantizer.Quantize(image); } return(base.Save(path, image)); }
/// <summary> /// Initializes a new instance of the <see cref="GifDecoder"/> class. /// </summary> /// <param name="image"> /// The <see cref="Image"/> to decode. /// </param> public GifDecoder(Image image) { this.Height = image.Height; this.Width = image.Width; if (FormatUtilities.IsAnimated(image)) { this.IsAnimated = true; if (this.IsAnimated) { int frameCount = image.GetFrameCount(FrameDimension.Time); int last = frameCount - 1; double length = 0; List <GifFrame> gifFrames = new List <GifFrame>(); // Get the times stored in the gif. byte[] times = image.GetPropertyItem((int)ExifPropertyTag.FrameDelay).Value; for (int i = 0; i < frameCount; i++) { // Convert each 4-byte chunk into an integer. // GDI returns a single array with all delays, while Mono returns a different array for each frame. TimeSpan delay = TimeSpan.FromMilliseconds(BitConverter.ToInt32(times, (4 * i) % times.Length) * 10); // Find the frame image.SelectActiveFrame(FrameDimension.Time, i); Bitmap frame = new Bitmap(image); frame.SetResolution(image.HorizontalResolution, image.VerticalResolution); // TODO: Get positions. gifFrames.Add(new GifFrame { Delay = delay, Image = frame }); // Reset the position. if (i == last) { image.SelectActiveFrame(FrameDimension.Time, 0); } length += delay.TotalMilliseconds; } this.GifFrames = gifFrames; this.AnimationLength = length; // Loop info is stored at byte 20737. this.LoopCount = BitConverter.ToInt16(image.GetPropertyItem((int)ExifPropertyTag.LoopCount).Value, 0); this.IsLooped = this.LoopCount != 1; } } }
/// <summary> /// Initializes a new instance of the <see cref="GifDecoder"/> class. /// </summary> /// <param name="image"> /// The <see cref="Image"/> to decode. /// </param> /// <param name="animationProcessMode"> /// The <see cref="AnimationProcessMode" /> to use. /// </param> public GifDecoder(Image image, AnimationProcessMode animationProcessMode) { this.Height = image.Height; this.Width = image.Width; if (FormatUtilities.IsAnimated(image) && animationProcessMode == AnimationProcessMode.All) { this.IsAnimated = true; this.FrameCount = image.GetFrameCount(FrameDimension.Time); // Loop info is stored at byte 20737. this.LoopCount = BitConverter.ToInt16(image.GetPropertyItem((int)ExifPropertyTag.LoopCount).Value, 0); } else { this.FrameCount = 1; } }