Ejemplo n.º 1
0
        private Stream EncodeBitmap(Bitmap1 bitmap, Guid containerFormat)
        {
            using (var bitmapEncoder = new BitmapEncoder(WicFactory, containerFormat))
            {
                var memoryStream = new MemoryStream();
                bitmapEncoder.Initialize(memoryStream);
                using (var frameEncode = new BitmapFrameEncode(bitmapEncoder))
                {
                    frameEncode.Initialize();
                    var wicPixelFormat = ImagePixelFormat;
                    frameEncode.SetPixelFormat(ref wicPixelFormat);

                    var imageParams = new ImageParameters()
                    {
                        PixelFormat = DevicePixelFormat,
                        DpiX        = Dpi,
                        DpiY        = Dpi,
                        PixelWidth  = bitmap.PixelSize.Width,
                        PixelHeight = bitmap.PixelSize.Height
                    };

                    WicImageEncoder.WriteFrame(bitmap, frameEncode, imageParams);

                    frameEncode.Commit();
                    bitmapEncoder.Commit();
                }

                memoryStream.Position = 0;
                return(memoryStream);
            }
        }
Ejemplo n.º 2
0
        public WicAnimatedGifEncoder(PipelineContext ctx, WicImageEncoder enc)
        {
            this.ctx = ctx;
            encoder  = enc;

            lastSource = ctx.Source;
            lastFrame  = ctx.ImageContainer.FrameCount - 1;

            EncodeFrame = new BufferFrame(lastSource.Width, lastSource.Height, lastSource.Format);
            for (int i = 0; i < frames.Length; i++)
            {
                frames[i] = new BufferFrame(lastSource.Width, lastSource.Height, lastSource.Format);
            }

            loadFrame(Current);
            Current.Source.Span.CopyTo(EncodeFrame.Source.Span);

            moveToFrame(1);
            loadFrame(Next !);
        }