コード例 #1
0
        public void Render(Aurigma.GraphicsMill.Bitmap canvas, float zoom, System.Drawing.Rectangle viewport, System.Drawing.Rectangle renderingRegion)
        {
            if (viewport.Width < 1 || viewport.Height < 1 || renderingRegion.Width < 1 || renderingRegion.Height < 1)
            {
                return;
            }

            if (canvas == null)
            {
                throw new System.ArgumentNullException("canvas");
            }
            if (canvas.IsEmpty)
            {
                throw new System.ArgumentException(StringResources.GetString("ExStrBitmapCannotBeEmpty"), "canvas");
            }
            if (!viewport.Contains(renderingRegion))
            {
                throw new System.ArgumentException(StringResources.GetString("ExStrRenderingRegionShouldBeInsideViewport"), "renderingRegion");
            }

            System.Drawing.Rectangle viewportInvalidatedRect = CoordinateMapper.WorkspaceToControl(this.InvalidatedRegion, zoom, System.Drawing.Point.Empty, Aurigma.GraphicsMill.Unit.Point, _renderingResolution);
            if (renderingRegion.IntersectsWith(viewportInvalidatedRect) || !_viewportCache.IsEntirelyInCache(zoom, renderingRegion))
            {
                BuildUpViewportImage(canvas, zoom, viewport, viewportInvalidatedRect);
                this.InvalidatedRegion = System.Drawing.RectangleF.Empty;
                _viewportCache.UpdateCache(canvas, zoom, viewport);
            }
            else
            {
                System.Diagnostics.Debug.Assert(_viewportCache.IsEntirelyInCache(zoom, renderingRegion), "At this point we should already have actual image in cache.");
                _viewportCache.DrawCached(canvas, zoom, viewport, renderingRegion);
            }
        }
コード例 #2
0
 public System.Drawing.Rectangle WorkspaceToControl(System.Drawing.RectangleF workspaceRect, Aurigma.GraphicsMill.Unit workspaceUnit)
 {
     return(CoordinateMapper.WorkspaceToControl(workspaceRect, _zoom, _viewport.Location, workspaceUnit, _resolution));
 }
コード例 #3
0
        public void Render(Aurigma.GraphicsMill.Bitmap canvas, float zoom, System.Drawing.Rectangle viewport, System.Drawing.Rectangle renderingRegion)
        {
            if (!_layer.Visible || _layer.VObjects.Count < 1)
            {
                return;
            }

            CoordinateMapper coordinateMapper = new CoordinateMapper();

            coordinateMapper.Viewport   = viewport;
            coordinateMapper.Zoom       = zoom;
            coordinateMapper.Resolution = _renderingResolution;

            renderingRegion.X -= viewport.X;
            renderingRegion.Y -= viewport.Y;

            System.IntPtr           dc    = System.IntPtr.Zero;
            System.IntPtr           oldDc = System.IntPtr.Zero;
            System.Drawing.Graphics g     = null;
            Aurigma.GraphicsMill.Drawing.Graphics gdiGraphics = null;

            try
            {
                // Read MSDN KB article "GDI & GDI+ interoperability". We should create System.Drawing.Graphics
                // from DC, not from Bitmap to avoid getting sentinel bitmap. Otherwise we will not be able to
                // blend images using Aurigma.GraphicsMill.Bitmap.Draw(System.Drawing.Graphics g, ...) method.
                //
                // The first branch is used when we render to the screen. In this case canvas has 24bppRgb format
                // and we just use its GDI graphics (most probably it has been already created by caching renderer) to
                // obtain HDC. Second branch is used when we render control content to 32bppArgb image - in such case
                // we cannot create GDI graphics and have to manually create DC and select canvas.Handle into it.
                if (canvas.PixelFormat == PixelFormat.Format24bppRgb)
                {
                    gdiGraphics = canvas.GetGraphics();
                    g           = System.Drawing.Graphics.FromHdc(gdiGraphics.GetDC());
                }
                else
                {
                    dc = NativeMethods.CreateCompatibleDC(System.IntPtr.Zero);

                    if (dc == System.IntPtr.Zero)
                    {
                        throw new Aurigma.GraphicsMill.UnexpectedException(StringResources.GetString("Cannot create compatible DC."));
                    }

                    g = System.Drawing.Graphics.FromHdc(dc);
                }

                g.SetClip(renderingRegion);

                for (int i = 0; i < _layer.VObjects.Count; i++)
                {
                    System.Drawing.Rectangle bounds = coordinateMapper.WorkspaceToControl(_layer.VObjects[i].GetTransformedVObjectBounds(), Aurigma.GraphicsMill.Unit.Point);

                    if (bounds.IntersectsWith(renderingRegion))
                    {
                        _layer.VObjects[i].Draw(renderingRegion, g, coordinateMapper);
                    }
                }
            }
            finally
            {
                if (g != null)
                {
                    g.Dispose();
                }

                if (gdiGraphics != null)
                {
                    gdiGraphics.Dispose();
                }

                if (dc != System.IntPtr.Zero)
                {
                    NativeMethods.SelectObject(dc, oldDc);
                    NativeMethods.DeleteDC(dc);
                }
            }
        }