diff options
author | Larry Ewing <lewing@xamarin.com> | 2018-04-12 01:56:41 +0300 |
---|---|---|
committer | Larry Ewing <lewing@microsoft.com> | 2018-07-16 22:05:48 +0300 |
commit | 6bb4a87cfdfdb1237d2b7749e63650fa976113e8 (patch) | |
tree | 2d221d4ffc073ec7c232eb1ffdbf385eb556c9fd /Xamarin.PropertyEditing.Mac/Controls/Custom | |
parent | 314e47ab7198f667185d4ba1598da6259ed6a199 (diff) |
Switch preview drawing to use CommonBrushLayer
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/Custom')
-rw-r--r-- | Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs index e17a7a1..38fa322 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs @@ -178,6 +178,25 @@ namespace Xamarin.PropertyEditing.Mac BrushLayer.Frame = new CGRect (0, 0, Frame.Width, Frame.Height); Contents = DrawingExtensions.GenerateCheckerboard (Frame); } + + public NSImage RenderPreview () + { + var scale = this.ContentsScale; + nint h = (nint)(this.Bounds.Height * scale); + nint w = (nint)(this.Bounds.Width * scale); + nint bytesPerRow = w * 4; + + if (h <= 0 || w <= 0) + return null; + + using (var colorSpace = CGColorSpace.CreateGenericRgb ()) + using (var context = new CGBitmapContext (IntPtr.Zero, w, h, 8, bytesPerRow, colorSpace, CGImageAlphaInfo.PremultipliedLast)) { + this.RenderInContext (context); + using (var image = context.ToImage ()) { + return new NSImage (image, new CGSize (w, h)); + } + } + } } class HistoryLayer : ColorEditorLayer |