Example #1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Debug.WriteLine("OnNavigatedTo");
            _resultframeRenderer    = new FrameRenderer(UIResultImage);
            _inputFrameRenderer     = new FrameRenderer(UIInputImage);
            UIStyleList.ItemsSource = _kModelFileNames;

            UIInkCanvasInput.InkPresenter.InputDeviceTypes =
                CoreInputDeviceTypes.Mouse
                | CoreInputDeviceTypes.Pen
                | CoreInputDeviceTypes.Touch;

            UIInkCanvasInput.InkPresenter.UpdateDefaultDrawingAttributes(
                new Windows.UI.Input.Inking.InkDrawingAttributes()
            {
                Color          = Windows.UI.Colors.Black,
                Size           = new Size(8, 8),
                IgnorePressure = true,
                IgnoreTilt     = true,
            }
                );

            // Select first style
            UIStyleList.SelectedIndex = 0;
        }
        /// <summary>
        /// Pass the input frame to a frame renderer and ensure proper image format is used
        /// </summary>
        /// <param name="inputVideoFrame"></param>
        /// <param name="useDX"></param>
        /// <returns></returns>
        public static IAsyncAction RenderFrameAsync(FrameRenderer frameRenderer, VideoFrame inputVideoFrame)
        {
            return(AsyncInfo.Run(async(token) =>
            {
                bool useDX = inputVideoFrame.SoftwareBitmap == null;
                if (frameRenderer == null)
                {
                    throw (new InvalidOperationException("FrameRenderer is null"));
                }

                SoftwareBitmap softwareBitmap = null;
                if (useDX)
                {
                    softwareBitmap = await SoftwareBitmap.CreateCopyFromSurfaceAsync(inputVideoFrame.Direct3DSurface);
                    softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
                }
                else
                {
                    softwareBitmap = inputVideoFrame.SoftwareBitmap;
                    //softwareBitmap = new SoftwareBitmap(
                    //    inputVideoFrame.SoftwareBitmap.BitmapPixelFormat,
                    //    inputVideoFrame.SoftwareBitmap.PixelWidth,
                    //    inputVideoFrame.SoftwareBitmap.PixelHeight,
                    //    inputVideoFrame.SoftwareBitmap.BitmapAlphaMode);
                    //inputVideoFrame.SoftwareBitmap.CopyTo(softwareBitmap);
                }

                frameRenderer.RenderFrame(softwareBitmap);
            }));
        }