Beispiel #1
0
        /// <summary>
        ///     Add a new frame to the GIF
        /// </summary>
        /// <param name="image">The image to add to the GIF stack</param>
        /// <param name="delay">The delay in milliseconds this GIF will be delayed (-1: Indicating class property delay)</param>
        /// <param name="quality">The GIFs quality</param>
        public void AddFrame(Image image, int delay = -1, GifQuality quality = GifQuality.Default)
        {
            var gif = new GifClass();

            gif.LoadGifPicture(image, quality);

            if (_stream == null)
            {
                _stream = new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.Read);
                _stream.Write(CreateHeaderBlock());
                _stream.Write(gif.ScreenDescriptor.ToArray());
                _stream.Write(CreateApplicationExtensionBlock(Repeat));
            }

            _stream.Write(CreateGraphicsControlExtensionBlock(delay > -1 ? delay : Delay));
            _stream.Write(gif.ImageDescriptor.ToArray());
            _stream.Write(gif.ColorTable.ToArray());
            _stream.Write(gif.ImageData.ToArray());

            FrameCount++;
        }
        /// <summary>
        ///     Add a new frame to the GIF
        /// </summary>
        /// <param name="image">The image to add to the GIF stack</param>
        /// <param name="delay">The delay in milliseconds this GIF will be delayed (-1: Indicating class property delay)</param>
        /// <param name="quality">The GIFs quality</param>
        public void AddFrame(Image image, int delay = -1, GifQuality quality = GifQuality.Default)
        {
            var gif = new GifClass();

            gif.LoadGifPicture(image, quality);

            if (!_createdHeader)
            {
                AppendToStream(CreateHeaderBlock());
                AppendToStream(gif.ScreenDescriptor.ToArray());
                AppendToStream(CreateApplicationExtensionBlock(Repeat));
                _createdHeader = true;
            }

            AppendToStream(CreateGraphicsControlExtensionBlock(delay > -1 ? delay : Delay));
            AppendToStream(gif.ImageDescriptor.ToArray());
            AppendToStream(gif.ColorTable.ToArray());
            AppendToStream(gif.ImageData.ToArray());

            FrameCount++;
        }
        /// <summary>
        ///     Add a new frame to the GIF async
        /// </summary>
        /// <param name="image">The image to add to the GIF stack</param>
        /// <param name="delay">The delay in milliseconds this GIF will be delayed (-1: Indicating class property delay)</param>
        /// <param name="quality">The GIFs quality</param>
        public async Task AddFrameAsync(Image image, int delay = -1, GifQuality quality = GifQuality.Default, CancellationToken cancellationToken = default(CancellationToken))
        {
            var gif = new GifClass();

            gif.LoadGifPicture(image, quality);

            if (!_createdHeader)
            {
                await AppendToStreamAsync(CreateHeaderBlock(), cancellationToken);
                await AppendToStreamAsync(gif.ScreenDescriptor.ToArray(), cancellationToken);
                await AppendToStreamAsync(CreateApplicationExtensionBlock(Repeat), cancellationToken);

                _createdHeader = true;
            }

            await AppendToStreamAsync(CreateGraphicsControlExtensionBlock(delay > -1 ? delay : Delay), cancellationToken);
            await AppendToStreamAsync(gif.ImageDescriptor.ToArray(), cancellationToken);
            await AppendToStreamAsync(gif.ColorTable.ToArray(), cancellationToken);
            await AppendToStreamAsync(gif.ImageData.ToArray(), cancellationToken);

            FrameCount++;
        }