Пример #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.LoadGifImage(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++;
        }
Пример #2
0
        /// <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.LoadGifImage(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++;
        }