public static NSImage GetBackgroundImage(this NSView control, Brush brush) { if (control == null || brush == null || brush.IsEmpty) { return(null); } var backgroundLayer = control.GetBackgroundLayer(brush); if (backgroundLayer == null) { return(null); } NSImage backgroundImage = new NSImage(new CGSize(backgroundLayer.Bounds.Width, backgroundLayer.Bounds.Height)); backgroundImage.LockFocus(); var context = NSGraphicsContext.CurrentContext.GraphicsPort; backgroundLayer.RenderInContext(context); backgroundImage.UnlockFocus(); return(backgroundImage); }