Esempio n. 1
0
        public Aurigma.GraphicsMill.Bitmap RenderWorkspace(float renderingResolution)
        {
            if (renderingResolution < VObject.Eps)
            {
                throw new System.ArgumentOutOfRangeException("renderingResolution", StringResources.GetString("ExStrValueShouldBeAboveZero"));
            }

            float workspaceWidth, workspaceHeight;

            Aurigma.GraphicsMill.Unit prevUnit = _hostViewer.Unit;
            _hostViewer.Unit = Aurigma.GraphicsMill.Unit.Point;
            try
            {
                workspaceWidth  = _hostViewer.WorkspaceWidth;
                workspaceHeight = _hostViewer.WorkspaceHeight;
            }
            finally
            {
                _hostViewer.Unit = prevUnit;
            }

            System.Drawing.Rectangle controlRectangle = CoordinateMapper.WorkspaceToControl(new System.Drawing.RectangleF(0, 0, workspaceWidth, workspaceHeight), 1.0f, System.Drawing.Point.Empty, Aurigma.GraphicsMill.Unit.Point, renderingResolution);
            controlRectangle.Width  = System.Math.Max(1, controlRectangle.Width);
            controlRectangle.Height = System.Math.Max(1, controlRectangle.Height);

            Aurigma.GraphicsMill.Bitmap result = new Aurigma.GraphicsMill.Bitmap(controlRectangle.Width, controlRectangle.Height, Aurigma.GraphicsMill.PixelFormat.Format32bppArgb, Aurigma.GraphicsMill.RgbColor.Transparent);
            try
            {
                using (var g = result.GetGdiPlusGraphics())
                {
                    CoordinateMapper coordMapper = new CoordinateMapper();
                    coordMapper.Resolution = renderingResolution;
                    coordMapper.Zoom       = 1.0f;
                    coordMapper.Viewport   = controlRectangle;

                    _alwaysUseGdiPlus = true;
                    DrawContent(g, controlRectangle, coordMapper);
                    _alwaysUseGdiPlus = false;
                }
            }
            catch
            {
                if (result != null)
                {
                    result.Dispose();
                }

                throw;
            }

            result.DpiX = renderingResolution;
            result.DpiY = renderingResolution;

            return(result);
        }