Пример #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()
        {
            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));
        }