From cf07825667aa444c988c82b7e29cefc5f8ba7bcd Mon Sep 17 00:00:00 2001 From: Christian Resma Helle Date: Thu, 24 Nov 2016 16:30:33 +0100 Subject: [PATCH] Improve UIScreen Capture() support for complex views (#1235) Use DrawViewHierarchy to capture a snapshot of the current screen --- src/UIKit/UIScreen.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/UIKit/UIScreen.cs b/src/UIKit/UIScreen.cs index c941673a3f..d2271da501 100644 --- a/src/UIKit/UIScreen.cs +++ b/src/UIKit/UIScreen.cs @@ -37,6 +37,18 @@ namespace XamCore.UIKit { public UIImage Capture () { + if (UIDevice.CurrentDevice.CheckSystemVersion (7, 0)) { + // This is from https://developer.apple.com/library/content/qa/qa1817/_index.html + try { + var view = UIApplication.SharedApplication.KeyWindow; + UIGraphics.BeginImageContextWithOptions (view.Bounds.Size, view.Opaque, 0); + view.DrawViewHierarchy (view.Bounds, true); + return UIGraphics.GetImageFromCurrentImageContext (); + } finally { + UIGraphics.EndImageContext (); + } + } + // This is from: https://developer.apple.com/library/ios/#qa/qa2010/qa1703.html var selScreen = new Selector ("screen"); var size = Bounds.Size;