Пример #1
0
        static Task <ScreenshotResult> PlatformCaptureAsync()
        {
            var img    = UIScreen.MainScreen.Capture();
            var result = new ScreenshotResult(img);

            return(Task.FromResult(result));
        }
Пример #2
0
        static Task <ScreenshotResult> PlatformCaptureAsync()
        {
            var scenes       = UIApplication.SharedApplication.ConnectedScenes;
            var currentScene = scenes.ToArray().Where(n => n.ActivationState == UISceneActivationState.ForegroundActive).FirstOrDefault();

            if (currentScene == null)
            {
                throw new InvalidOperationException("Unable to find current scene.");
            }

            var uiWindowScene = currentScene as UIWindowScene;

            if (uiWindowScene == null)
            {
                throw new InvalidOperationException("Unable to find current uiwindow scene.");
            }

            var currentWindow = uiWindowScene.Windows.FirstOrDefault(n => n.IsKeyWindow);

            if (currentWindow == null)
            {
                throw new InvalidOperationException("Unable to find current window.");
            }

            var image  = currentWindow.Render(currentWindow.Layer, UIScreen.MainScreen.Scale);
            var result = new ScreenshotResult(image);

            return(Task.FromResult(result));
        }
Пример #3
0
        static Task <ScreenshotResult> PlatformCaptureAsync()
        {
            if (Platform.WindowManager?.DefaultDisplay?.Flags.HasFlag(DisplayFlags.Secure) == true)
            {
                throw new UnauthorizedAccessException("Unable to take a screenshot of a secure window.");
            }

            var view = Platform.GetCurrentActivity(true)?.Window?.DecorView?.RootView;

            if (view == null)
            {
                throw new NullReferenceException("Unable to find the main window.");
            }

            var bitmap = Bitmap.CreateBitmap(view.Width, view.Height, Bitmap.Config.Argb8888);

            using (var canvas = new Canvas(bitmap))
            {
                var drawable = view.Background;
                if (drawable != null)
                {
                    drawable.Draw(canvas);
                }
                else
                {
                    canvas.DrawColor(Color.White);
                }

                view.Draw(canvas);
            }

            var result = new ScreenshotResult(bitmap);

            return(Task.FromResult(result));
        }
Пример #4
0
        static Task <ScreenshotResult> PlatformCaptureAsync()
        {
            if (Platform.WindowManager?.DefaultDisplay?.Flags.HasFlag(DisplayFlags.Secure) == true)
            {
                throw new UnauthorizedAccessException("Unable to take a screenshot of a secure window.");
            }

            var view = Platform.GetCurrentActivity(true)?.Window?.DecorView?.RootView;

            if (view == null)
            {
                throw new NullReferenceException("Unable to find the main window.");
            }

            var result = new ScreenshotResult(view.Render());

            return(Task.FromResult(result));
        }