Exemple #1
0
        public int Finish(string path)
        {
            if (this.bkGifEncoder == null)
            {
                return(1);
            }

            try
            {
                this.bkGifEncoder.Dispose();
                this.bkGifEncoder = null;
                this.tempFileStream.Flush();
                this.tempFileStream.Close();
            }
            catch (System.Exception)
            {
                return(2);
            }

            try
            {
                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
                System.IO.File.Move(this.tempFile, path);
            }
            catch (System.Exception)
            {
                return(3);
            }

            return(0);
        }
        public void AddImage(object frameObj)
        {
            System.Drawing.Bitmap frame = (System.Drawing.Bitmap)frameObj;

            // Not sure why this is getting flipped during the encoding process, so
            // pre-flip it as a workaround.
            frame.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);

            int width  = frame.Width;
            int height = frame.Height;

            if (bkGifEncoder == null)
            {
                this.expectedWidth  = width;
                this.expectedHeight = height;
                this.tempFileStream = System.IO.File.Create(this.tempFile);
                this.bkGifEncoder   = new BumpKitGifEncoder(this.tempFileStream, width, height);
            }
            else
            {
                if (this.expectedWidth != width || this.expectedHeight != height)
                {
                    // TODO: error code
                    throw new System.Exception();
                }
            }

            this.bkGifEncoder.AddFrame(frame, 0, 0, System.TimeSpan.FromMilliseconds(this.millisPerFrame));
        }
Exemple #3
0
        public void AddImage(object frameObj)
        {
            System.Drawing.Bitmap frame = (System.Drawing.Bitmap)frameObj;

            // Not sure why this is getting flipped during the encoding process, so
            // pre-flip it as a workaround.
            frame.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);

            int width  = frame.Width;
            int height = frame.Height;

            if (bkGifEncoder == null)
            {
                this.expectedWidth  = width;
                this.expectedHeight = height;
                int fileWidth  = this.expectedWidth;
                int fileHeight = this.expectedHeight;
                if (this.useOutputSize)
                {
                    fileWidth  = this.outputWidth;
                    fileHeight = this.outputHeight;
                }
                this.tempFileStream = System.IO.File.Create(this.tempFile);
                this.bkGifEncoder   = new BumpKitGifEncoder(this.tempFileStream, fileWidth, fileHeight);
            }
            else
            {
                if (this.expectedWidth != width || this.expectedHeight != height)
                {
                    // TODO: error code
                    throw new System.Exception();
                }
            }

            if (this.useOutputSize &&
                (this.outputWidth != this.expectedWidth || this.outputHeight != this.expectedHeight))
            {
                System.Drawing.Bitmap newFrame = new System.Drawing.Bitmap(this.outputWidth, this.outputHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newFrame))
                {
                    g.DrawImage(frame, 0, 0, this.outputWidth, this.outputHeight);
                }
                frame = newFrame;
            }

            this.bkGifEncoder.AddFrame(frame, 0, 0, System.TimeSpan.FromMilliseconds(this.millisPerFrame));
        }