/// <summary> /// BeforeRender - Make sure we have a Graphics object to render to. /// If we don't have one, then create one to match the SvgWindow's /// physical dimensions. /// </summary> private void RendererBeforeRender() { // Testing for null here allows "advanced" developers to create their own Graphics object for rendering if (graphics == null) { // Get the current SVGWindow's width and height int innerWidth = (int)window.InnerWidth; int innerHeight = (int)window.InnerHeight; // Make sure we have an actual area to render to if (innerWidth > 0 && innerHeight > 0) { // See if we already have a rasterImage that matches the current SVGWindow dimensions if (rasterImage == null || rasterImage.Width != innerWidth || rasterImage.Height != innerHeight) { // Nope, so create one if (rasterImage != null) { rasterImage.Dispose(); rasterImage = null; } rasterImage = new Bitmap(innerWidth, innerHeight); } // Maybe we are only repainting an invalidated section if (invalidRect != SvgRectF.Empty) { // TODO: Worry about pan... if (invalidRect.X < 0) { invalidRect.X = 0; } if (invalidRect.Y < 0) { invalidRect.Y = 0; } if (invalidRect.Right > innerWidth) { invalidRect.Width = innerWidth - invalidRect.X; } if (invalidRect.Bottom > innerHeight) { invalidRect.Height = innerHeight - invalidRect.Y; } if (invalidatedRasterImage == null || invalidatedRasterImage.Width < invalidRect.Right || invalidatedRasterImage.Height < invalidRect.Bottom) { // Nope, so create one if (invalidatedRasterImage != null) { invalidatedRasterImage.Dispose(); invalidatedRasterImage = null; } invalidatedRasterImage = new Bitmap((int)invalidRect.Right, (int)invalidRect.Bottom); } // Make a GraphicsWrapper object from the regionRasterImage and clear it to the background color graphics = GdiGraphicsWrapper.FromImage(invalidatedRasterImage, false); graphics.Clear(backColor); } else { // Make a GraphicsWrapper object from the rasterImage and clear it to the background color graphics = GdiGraphicsWrapper.FromImage(rasterImage, false); graphics.Clear(backColor); } } } }
public static GdiGraphics Create(Image image, bool isStatic) { return(GdiGraphicsWrapper.FromImage(image, isStatic)); }