Exemple #1
0
        public static Bitmap DeepCloneGif(Image source, bool preserveMetaData = true)
        {
            GifDecoder decoder = new GifDecoder(source);
            GifEncoder encoder = new GifEncoder(decoder.LoopCount);

            for (int i = 0; i < decoder.FrameCount; i++)
            {
                using (GifFrame frame = decoder.GetFrame(i))
                {
                    encoder.EncodeFrame(frame);
                }
            }

            Image copy = encoder.Encode();

            if (preserveMetaData)
            {
                ImageHelper.CopyMetadata(source, copy);
            }

            return((Bitmap)copy);
        }
Exemple #2
0
        /// <summary>
        /// Decode a gif, apply the given <see cref="RotateFlipType"/> and return the re-encoded the gif.
        /// </summary>
        /// <param name="bmp">The gif to process.</param>
        /// <param name="rotateFlip">The <see cref="RotateFlipType"/> to apply.</param>
        /// <returns>A rotated flipped gif based on the <see cref="RotateFlipType"/>; otherwise null.</returns>
        public static Bitmap RotateFlipGif(Bitmap bmp, RotateFlipType rotateFlip)
        {
            try
            {
                GifDecoder d = new GifDecoder(bmp);
                GifEncoder e = new GifEncoder(d.LoopCount);

                for (int i = 0; i < d.FrameCount; i++)
                {
                    using (GifFrame frame = d.GetFrame(i))
                    {
                        frame.Image.RotateFlip(rotateFlip);
                        e.EncodeFrame(frame);
                    }
                }
                return((Bitmap)e.Encode());
            }
            catch
            {
                return(null);
            }
        }
Exemple #3
0
        /// <summary>
        /// Invert the colors of every frame of a bitmap with animated frames.
        /// </summary>
        /// <param name="bmp"> The bitmap to invert. </param>
        /// <returns></returns>
        public static Bitmap InvertGif(Bitmap bmp)
        {
            try
            {
                GifDecoder d = new GifDecoder(bmp);
                GifEncoder e = new GifEncoder(d.LoopCount);

                for (int i = 0; i < d.FrameCount; i++)
                {
                    using (GifFrame frame = d.GetFrame(i))
                    {
                        InvertBitmapSafe(frame.Image);
                        e.EncodeFrame(frame);
                    }
                }
                return((Bitmap)e.Encode());
            }
            catch
            {
                return(null);
            }
        }