protected override void UpdateCapturedImage() { // This is somewhat misnomered because it's not _just_ a ViewRenderer anymore, but // changing it seems unnecesssary. if (view != null && layer == null) { CapturedImage = ViewRenderer.RenderAsPng(view.Window, view, UIScreen.MainScreen.Scale); } else if (layer != null) { CapturedImage = ViewRenderer.RenderAsPng(view.Window, layer, UIScreen.MainScreen.Scale); } }
/// <summary> /// Creates a new <see cref="T:Xamarin.Interactive.iOS.iOSInspectView"/> that represents the given layer. /// </summary> /// <param name="parent">The parent view of the layer.</param> /// <param name="layer">The layer itself.</param> /// <param name="visitedLayers"> /// Layers we've already visited in building this tree. This method both checks sublayers against this /// collection and modifies it by adding sublayers it consumes. /// </param> /// <param name="withSublayers">If <c>true</c>, descend into sublayers of this layer.</param> /// <remarks> /// We need to keep track of this set of visited layers to avoid an oddity in the way that layers are /// presented in the UIKit "tree." Layers and views are actually two separate trees, with the layer /// tree being a child tree of the top-level UIWindow, and the individual layer properties of each /// UIView being pointers into various places in that tree. /// </remarks> public iOSInspectView(UIView parent, CALayer layer, HashSet <IntPtr> visitedLayers, bool withSublayers = true) { if (parent == null) { throw new ArgumentNullException(nameof(parent)); } if (layer == null) { throw new ArgumentNullException(nameof(layer)); } view = parent; this.layer = layer; SetHandle(ObjectCache.Shared.GetHandle(layer)); PopulateTypeInformationFromObject(layer); Description = layer.Description; Transform = ViewRenderer.GetViewTransform(layer); if (Transform != null) { X = layer.Bounds.X; Y = layer.Bounds.Y; Width = layer.Bounds.Width; Height = layer.Bounds.Height; } else { X = layer.Frame.X; Y = layer.Frame.Y; Width = layer.Frame.Width; Height = layer.Frame.Height; } Kind = ViewKind.Secondary; // iOS doesn't have a concept of hidden but laid out, so it's either collapsed or visible. Visibility = layer.Hidden ? ViewVisibility.Collapsed : ViewVisibility.Visible; if (!withSublayers) { var point = view.ConvertPointToView( new CoreGraphics.CGPoint(X, Y), null); X = point.X; Y = point.Y; return; } var sublayers = layer.Sublayers; if (sublayers != null && sublayers.Length > 0) { for (int i = 0; i < sublayers.Length; i++) { if (!visitedLayers.Contains(sublayers [i].Handle)) { AddSublayer(new iOSInspectView(parent, sublayers [i], visitedLayers)); visitedLayers.Add(sublayers [i].Handle); } } } }
public UIImage Capture(float?scale = null) { return(ViewRenderer.Render(view.Window, view, scale == null ? UIScreen.MainScreen.Scale : scale.Value)); }