예제 #1
0
        public static async Task <SoftwareBitmap> CaptureVisualAsync(this UIElement element, uint captureWidth = 0, uint captureHeight = 0)
        {
            uint width  = captureWidth;
            uint height = captureHeight;

            UIExecutor.Execute(() =>
            {
                var frameworkElement = element as FrameworkElement;
                if (width == 0)
                {
                    if (frameworkElement != null)
                    {
                        width = (uint)frameworkElement.ActualWidth;
                    }
                }
                if (height == 0)
                {
                    if (frameworkElement != null)
                    {
                        height = (uint)frameworkElement.ActualHeight;
                    }
                }
            });

            var visual = element.GetVisual();

            return(await visual.CaptureVisualAsync(width, height));
        }
예제 #2
0
        private static ICompositionCaptureTest GetCompositionCaptureTest(this Visual visual)
        {
            var captureTest = default(ICompositionCaptureTest);

            UIExecutor.Execute(() =>
            {
                var compositor = visual.Compositor;
                captureTest    = ((object)compositor) as ICompositionCaptureTest;
            });
            return(captureTest);
        }
예제 #3
0
        public static Visual GetVisual(this UIElement element)
        {
            var visual = default(Visual);

            UIExecutor.Execute(() =>
            {
                visual = Windows.UI.Xaml.Hosting.ElementCompositionPreview.GetElementVisual(element);
                while (visual.Parent != null)
                {
                    visual = visual.Parent;
                }
            });
            return(visual);
        }
예제 #4
0
        public static async Task CaptureWindowAsync(this Window window, string id)
        {
            var  visual = default(Visual);
            uint height = 0;
            uint width  = 0;

            UIExecutor.Execute(() =>
            {
                height      = (uint)window.Bounds.Height;
                width       = (uint)window.Bounds.Width;
                var element = window.Content as UIElement;
                visual      = element.GetVisual();
                while (visual.Parent != null)
                {
                    visual = visual.Parent;
                }
            });
            using (var bitmap = await visual.CaptureVisualAsync(width, height))
            {
                await bitmap.LogAsync(id);
            }
        }