void DrawSample(Graphics graphics) { using (graphics.Platform.Context) { graphics.FillRectangle(Brushes.Green, 0, 0, 200, 200); if (UseGraphicsPathClip) { var path = GraphicsPath.GetRoundRect(new RectangleF(10, 10, 180, 180), 20); graphics.SetClip(path); } else graphics.SetClip(new RectangleF(10, 10, 180, 180)); if (UseClearColor) graphics.Clear(new SolidBrush(new Color(Colors.Red, 0.5f))); else graphics.Clear(); graphics.FillEllipse(Brushes.Blue, 25, 25, 150, 150); } }
protected sealed override void OnPaint(PaintEventArgs e) { if (EnableDoubleBuffering) { var screen = ParentWindow.Screen; var scale = screen.RealScale / screen.Scale; renderSize = Size.Round(e.ClipRectangle.Size * scale); if (bitmap == null || bitmap.Size.Width < renderSize.Width || bitmap.Size.Height < renderSize.Height) { if (bitmap != null) bitmap.Dispose(); bitmap = new Bitmap(renderSize, PixelFormat.Format32bppRgba); } var bitmapGraphics = new Graphics(bitmap); bitmapGraphics.Clear(Brushes.Cached(BackgroundColor)); bitmapGraphics.ScaleTransform(scale); bitmapGraphics.TranslateTransform(-e.ClipRectangle.Location); bitmapGraphics.SetClip(e.ClipRectangle * scale); // should be affected by transform var childArgs = new PaintEventArgs(bitmapGraphics, e.ClipRectangle); base.OnPaint(childArgs); OnBufferedPaint(childArgs); bitmapGraphics.Dispose(); bitmapGraphics = null; e.Graphics.DrawImage(bitmap, new RectangleF(renderSize), e.ClipRectangle); if (Platform.IsWpf) { // wpf runs out of resources fast here, so we garbage collect GC.Collect(); } } else { base.OnPaint(e); OnBufferedPaint(e); } }
public Graphics BeginDraw(PaintEventArgs e) { if (UseOffScreenBitmap) { if (OffscreenBitmap == null || OffscreenBitmap.Size.Width < e.ClipRectangle.Width || OffscreenBitmap.Size.Height < e.ClipRectangle.Height) { if (OffscreenBitmap != null) OffscreenBitmap.Dispose(); OffscreenBitmap = new Bitmap(Size.Round(e.ClipRectangle.Size), PixelFormat.Format32bppRgba); } bitmapGraphics = new Graphics(OffscreenBitmap); bitmapGraphics.TranslateTransform(-e.ClipRectangle.Location); bitmapGraphics.SetClip(e.ClipRectangle); bitmapGraphics.Clear(Brushes.Cached(drawable.BackgroundColor)); return bitmapGraphics; } return e.Graphics; }