/// <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);*/ softwareBitmap = SoftwareBitmap.Convert(inputVideoFrame.SoftwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); } frameRenderer.RenderFrame(softwareBitmap); })); }
protected async override void OnNavigatedTo(NavigationEventArgs e) { Debug.WriteLine("OnNavigatedTo"); try { // Instatiate skill descriptor to display details about the skill and populate UI m_skillDescriptor = new NeuralStyleTransformerDescriptor(); m_availableExecutionDevices = await m_skillDescriptor.GetSupportedExecutionDevicesAsync(); // Show skill description members in UI UISkillName.Text = m_skillDescriptor.Name; UISkillDescription.Text = SkillHelper.SkillHelperMethods.GetSkillDescriptorString(m_skillDescriptor); int featureIndex = 0; foreach (var featureDesc in m_skillDescriptor.InputFeatureDescriptors) { UISkillInputDescription.Text += SkillHelper.SkillHelperMethods.GetSkillFeatureDescriptorString(featureDesc); if (featureIndex++ < m_skillDescriptor.InputFeatureDescriptors.Count - 1) { UISkillInputDescription.Text += "\n----\n"; } } featureIndex = 0; foreach (var featureDesc in m_skillDescriptor.OutputFeatureDescriptors) { UISkillOutputDescription.Text += SkillHelper.SkillHelperMethods.GetSkillFeatureDescriptorString(featureDesc); if (featureIndex++ < m_skillDescriptor.OutputFeatureDescriptors.Count - 1) { UISkillOutputDescription.Text += "\n----\n"; } } if (m_availableExecutionDevices.Count == 0) { UISkillOutputDetails.Text = "No execution devices available, this skill cannot run on this device"; } else { // Display available execution devices UISkillExecutionDevices.ItemsSource = m_availableExecutionDevices.Select((device) => device.Name).ToList(); UISkillExecutionDevices.SelectedIndex = 0; // Alow user to interact with the app UIButtonFilePick.IsEnabled = true; UIButtonFilePick.Focus(FocusState.Keyboard); } } catch (Exception ex) { await new MessageDialog(ex.Message).ShowAsync(); } _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; // Create a 1 second timer _FramesPerSecondTimer.Tick += _FramesPerSecond_Tick; _FramesPerSecondTimer.Interval = new TimeSpan(0, 0, 1); _FramesPerSecondTimer.Start(); }