public /* Interface KGuiControl */ void GuiChartSnap() { if (NSThread.IsMain) { CGBitmapContext theCanvas = null; // store the canvas internally generated by GenPainter for use by DoPaste Func <Colorer> GenColorer = () => { return(new CGColorer()); }; Func <SKSize, ChartPainter> GenPainter = (SKSize canvasSize) => { CGBitmapContext canvas = CG.Bitmap((int)canvasSize.Width, (int)canvasSize.Height); CG.FlipCoordinateSystem(canvas); theCanvas = canvas; return(new CGChartPainter(canvas)); }; Action <CGBitmapContext> DoPaste = (CGBitmapContext canvas) => { var pasteboard = NSPasteboard.GeneralPasteboard; pasteboard.ClearContents(); pasteboard.WriteObjects(new NSImage[] { new NSImage(canvas.ToImage(), new CGSize(canvas.Width, canvas.Height)) }); }; CGSize cgChartSize = this.kaemikaChart.Frame.Size; Export.Snap(GenColorer, GenPainter, new SKSize((float)cgChartSize.Width, (float)cgChartSize.Height)); try { DoPaste(theCanvas); } catch { } } else { _ = BeginInvokeOnMainThreadAsync(() => { GuiChartSnap(); return(ack); }).Result; } }
// Implement this to draw on the canvas. public override void DrawRect(CGRect dirtyRect) { base.DrawRect(dirtyRect); var context = NSGraphicsContext.CurrentContext.CGContext; CG.FlipCoordinateSystem(context); KDeviceHandler.Draw(new CGDevicePainter(context), 0, 0, (int)dirtyRect.Width, (int)dirtyRect.Height); }