protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); draw.IsEnabled = false; _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(renderTimeout); _timer.Tick += _timer_Tick; await Task.Run(async () => { _bot = new HBot( HBotPin_AStep, HBotPin_ADir, HBotPin_AEn, HBotPin_BStep, HBotPin_BDir, HBotPin_BEn, HBotPin_XHome, HBotPin_YHome); _bot.setInfo(HBotBed_Width, HBotBed_Height, HBotBed_StepsPerMM); _pen = new PenActuator(HBotPin_PenServo); _pen.raise(); await Task.Delay(kPenMoveTimeout); _bot.enable(); _bot.home(); while (_bot.run()) ; _bot.disable(); }); _mediaCaptureMgr = new Windows.Media.Capture.MediaCapture(); await _mediaCaptureMgr.InitializeAsync(new MediaCaptureInitializationSettings { StreamingCaptureMode = StreamingCaptureMode.Video }); VideoEncodingProperties smallestMedia = null; var cameraProperties = _mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Select(x => x as VideoEncodingProperties).ToList(); if (cameraProperties.Count >= 1) { foreach (var mediaEncodingProperty in cameraProperties) { if (smallestMedia == null || (smallestMedia.Width > mediaEncodingProperty.Width || smallestMedia.Height > mediaEncodingProperty.Height)) { smallestMedia = mediaEncodingProperty; } } } cameraWidth = smallestMedia.Width; cameraHeight = smallestMedia.Height; await _mediaCaptureMgr.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, smallestMedia); CapturePreview.Width = cameraWidth; CapturePreview.Height = cameraHeight; CapturePreview.Source = _mediaCaptureMgr; await _mediaCaptureMgr.StartPreviewAsync(); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); draw.IsEnabled = false; _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(renderTimeout); _timer.Tick += _timer_Tick; await Task.Run(async() => { _bot = new HBot( HBotPin_AStep, HBotPin_ADir, HBotPin_AEn, HBotPin_BStep, HBotPin_BDir, HBotPin_BEn, HBotPin_XHome, HBotPin_YHome); _bot.setInfo(HBotBed_Width, HBotBed_Height, HBotBed_StepsPerMM); _pen = new PenActuator(HBotPin_PenServo); _pen.raise(); await Task.Delay(kPenMoveTimeout); _bot.enable(); _bot.home(); while (_bot.run()) { ; } _bot.disable(); }); _mediaCaptureMgr = new Windows.Media.Capture.MediaCapture(); await _mediaCaptureMgr.InitializeAsync(new MediaCaptureInitializationSettings { StreamingCaptureMode = StreamingCaptureMode.Video }); VideoEncodingProperties smallestMedia = null; var cameraProperties = _mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Select(x => x as VideoEncodingProperties).ToList(); if (cameraProperties.Count >= 1) { foreach (var mediaEncodingProperty in cameraProperties) { if (smallestMedia == null || (smallestMedia.Width > mediaEncodingProperty.Width || smallestMedia.Height > mediaEncodingProperty.Height)) { smallestMedia = mediaEncodingProperty; } } } cameraWidth = smallestMedia.Width; cameraHeight = smallestMedia.Height; await _mediaCaptureMgr.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, smallestMedia); CapturePreview.Width = cameraWidth; CapturePreview.Height = cameraHeight; CapturePreview.Source = _mediaCaptureMgr; await _mediaCaptureMgr.StartPreviewAsync(); }