示例#1
0
        /// <summary>Creates a screen shot of the canvas.</summary>
        /// <param name="draw">The method containing the commands for drawing to the canvas.</param>
        /// <returns>A screen-shot of the canvas.</returns>
        public Bitmap CreateScreenshot(Controls.DrawEventHandler draw)
        {
            var oldScale = _scale;
            var oldRect = canvasRect;
            var oldGfx = Graphics;

            var bmp = new Bitmap(Size.Width, Size.Height);
            using (var g = Graphics.FromImage(bmp))
            {
                this._scale = 1;
                this.Graphics = g;
                this.canvasRect = new RectangleF(Point.Empty, this.Size);
                draw.Invoke(this);
            }

            this._scale = oldScale;
            this.Graphics = oldGfx;
            this.canvasRect = oldRect;

            return bmp;
        }