StartPreviewAsync() public méthode

public StartPreviewAsync ( ) : IAsyncAction
Résultat IAsyncAction
Exemple #1
0
        private async Task intializeCamera()
        {
            if (captureManager == null)
            {
                captureManager = new MediaCapture();
                await captureManager.InitializeAsync();
            }

            capturePreview.Source = captureManager;
            await captureManager.StartPreviewAsync();

            try
            {
                play("This is add product page");
            }
            catch (System.IO.FileNotFoundException)
            {
                var messageDialog = new Windows.UI.Popups.MessageDialog("Media player components unavailable");
                await messageDialog.ShowAsync();
            }
            catch (Exception)
            {
                media.AutoPlay = false;
                var messageDialog = new Windows.UI.Popups.MessageDialog("Unable to synthesize text");
                await messageDialog.ShowAsync();
            }
        }
        private async void This_Loaded( object sender, RoutedEventArgs e )
        {
            try
            {
                _camera = new MediaCapture();
                await _camera.InitializeAsync( new MediaCaptureInitializationSettings
                {
                    VideoDeviceId = ( await GetBackCameraAsync() ).Id,
                    StreamingCaptureMode = StreamingCaptureMode.Video,
                    PhotoCaptureSource = PhotoCaptureSource.VideoPreview
                } );
                _camera.VideoDeviceController.FlashControl.Enabled = false;
                _camera.SetPreviewRotation( VideoRotation.Clockwise90Degrees );
                _camera.SetRecordRotation( VideoRotation.Clockwise90Degrees );

                CameraPreview.Source = _camera;
                await _camera.StartPreviewAsync();

                StartScanning();
            }
            catch
            {
                ErrorMessage.Visibility = Visibility.Visible;
            }
        }
        private async Task GetCapturePreview()
        {
            _capture = new MediaCapture();
            var Videodevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
            //var rearCamera = Videodevices.FirstOrDefault(item => item.EnclosureLocation != null && item.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
            var frontCamera = Videodevices.FirstOrDefault(item => item.EnclosureLocation != null && item.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front);
            //TODO: カメラを切り替えられるようにする。



            try
            {
                await _capture.InitializeAsync(new MediaCaptureInitializationSettings
                {
                    VideoDeviceId = frontCamera.Id
                });
            }
            catch (Exception ex)
            {
                var message = new MessageDialog(ex.Message, "おや?なにかがおかしいようです。");
                await message.ShowAsync();
            }

            capturePreview.Source = _capture;

            await _capture.StartPreviewAsync();
        }
Exemple #4
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            Status.Text = "Status: " + "App started";

            //compass
            var compass = Windows.Devices.Sensors.Compass.GetDefault();
            compass.ReportInterval = 10;
            //compass.ReadingChanged += compass_ReadingChanged;
            Status.Text = "Status: " + "Compass started";

            //geo
            var gloc = new Geolocator();
            gloc.GetGeopositionAsync();
            gloc.ReportInterval = 60000;
            gloc.PositionChanged += gloc_PositionChanged;
            Status.Text = "Status: " + "Geo started";

            //Accelerometer
            var aclom = Accelerometer.GetDefault();
            aclom.ReportInterval = 1;
            aclom.ReadingChanged += aclom_ReadingChanged;

            //foursquare
            await GetEstablishmentsfromWed();

            //camera
            var mediaCapture = new MediaCapture();
            await mediaCapture.InitializeAsync();
            CaptureElement.Source = mediaCapture;
            await mediaCapture.StartPreviewAsync();
            Status.Text = "Status: " + "Camera feed running";
        }
Exemple #5
0
 private async void Loaded(object sender, RoutedEventArgs e)
 {
     MediaCapture capMana = new MediaCapture();
     await capMana.InitializeAsync();
     Webcam_Logitech.Source = capMana;
     await capMana.StartPreviewAsync();
 }
 async private void Start_Capture_Preview_Click(object sender, RoutedEventArgs e)
 {
     captureManager = new MediaCapture();        //Define MediaCapture object
     await captureManager.InitializeAsync();     //Initialize MediaCapture and 
     capturePreview.Source = captureManager;     //Start preiving on CaptureElement
     await captureManager.StartPreviewAsync();   //Start camera capturing 
 }
 public async Task StartPreviewAsync(VideoRotation videoRotation)
 {
     try
     {
         if (mediaCapture == null)
         {
             var cameraDevice = await FindCameraDeviceByPanelAsync(Panel.Back);
             mediaCapture = new MediaCapture();
             var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };
             await mediaCapture.InitializeAsync(settings);
             captureElement.Source = mediaCapture;
             await mediaCapture.StartPreviewAsync();
             isPreviewing = true;
             mediaCapture.SetPreviewRotation(videoRotation);
             displayRequest.RequestActive();
         }
         //DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;
     }
     catch (UnauthorizedAccessException)
     {
         // This will be thrown if the user denied access to the camera in privacy settings
         Debug.WriteLine("The app was denied access to the camera");
     }
     catch (Exception ex)
     {
         Debug.WriteLine("MediaCapture initialization failed. {0}", ex.Message);
     }
 }
Exemple #8
0
        internal async void btnStartPreview_Click(Object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            m_bPreviewing = false;
            try
            {
                ShowStatusMessage("Starting preview");
                EnableButton(false, "StartPreview");

                previewCanvas1.Visibility = Windows.UI.Xaml.Visibility.Visible;
                previewElement1.Source    = m_mediaCaptureMgr;
                await m_mediaCaptureMgr.StartPreviewAsync();

                if ((m_mediaCaptureMgr.VideoDeviceController.Brightness != null) && m_mediaCaptureMgr.VideoDeviceController.Brightness.Capabilities.Supported)
                {
                    SetupVideoDeviceControl(m_mediaCaptureMgr.VideoDeviceController.Brightness, sldBrightness);
                }
                if ((m_mediaCaptureMgr.VideoDeviceController.Contrast != null) && m_mediaCaptureMgr.VideoDeviceController.Contrast.Capabilities.Supported)
                {
                    SetupVideoDeviceControl(m_mediaCaptureMgr.VideoDeviceController.Contrast, sldContrast);
                }
                m_bPreviewing = true;
                ShowStatusMessage("Start preview successful");
            }
            catch (Exception exception)
            {
                m_bPreviewing          = false;
                previewElement1.Source = null;
                EnableButton(true, "StartPreview");
                ShowExceptionMessage(exception);
            }
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (_mediaCapture == null)
            {
                // Attempt to get te back camera if one is available, but use any camera device if not
                var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

                DeviceInformation desiredDevice = allVideoDevices.FirstOrDefault(
                    x => x.EnclosureLocation != null & x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);

                var cameraDevice = desiredDevice ?? allVideoDevices.FirstOrDefault();

                if (cameraDevice == null)
                {
                    // TODO: Implement an error experience for camera-less devices
                    Debug.Write("No camera device found.");
                    return;
                }

                // Create MediaCapture and its setings
                _mediaCapture = new MediaCapture();
                var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };

                // TODO: Implement an error experience for non-authorized case
                await _mediaCapture.InitializeAsync(settings);

                // Startin the preview
                PreviewControl.Source = _mediaCapture;
                await _mediaCapture.StartPreviewAsync();
            }
        }
        private async void Grid_Loaded(object sender, RoutedEventArgs e)
        {
            var camera = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture)).FirstOrDefault();

            if (camera != null)
            {
                mediaCapture = new MediaCapture();
                var settings = new MediaCaptureInitializationSettings() { VideoDeviceId = camera.Id };
                await mediaCapture.InitializeAsync(settings);
                displayRequest.RequestActive();
                VideoPreview.Source = mediaCapture;
                await mediaCapture.StartPreviewAsync();

                memStream = new InMemoryRandomAccessStream();
                MediaEncodingProfile mediaEncodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
                await mediaCapture.StartRecordToStreamAsync(mediaEncodingProfile, memStream);
            }
            //video = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Video);
            //if (video!=null)
            //{
            //    MediaClip mediaClip = await MediaClip.CreateFromFileAsync(video);
            //    mediaComposition.Clips.Add(mediaClip);
            //    mediaStreamSource = mediaComposition.GeneratePreviewMediaStreamSource(600, 600);
            //    VideoPreview.SetMediaStreamSource(mediaStreamSource);
            //}
            //FFMPEGHelper.RTMPEncoder encoder = new FFMPEGHelper.RTMPEncoder();
            //encoder.Initialize("rtmp://youtube.co");
        }
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            mediaCapture = new MediaCapture();
            DeviceInformationCollection devices =
        await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            // Use the front camera if found one
            if (devices == null) return;
            DeviceInformation info = devices[0];

            foreach (var devInfo in devices)
            {
                if (devInfo.Name.ToLowerInvariant().Contains("front"))
                {
                    info = devInfo;
                    frontCam = true;
                    continue;
                }
            }

            await mediaCapture.InitializeAsync(
                new MediaCaptureInitializationSettings
                {
                    VideoDeviceId = info.Id
                });

            captureElement.Source = mediaCapture;
            captureElement.FlowDirection = frontCam ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
            await mediaCapture.StartPreviewAsync();

            DisplayInformation displayInfo = DisplayInformation.GetForCurrentView();
            displayInfo.OrientationChanged += DisplayInfo_OrientationChanged;

            DisplayInfo_OrientationChanged(displayInfo, null);
        }
        private async Task StartCamera()
        {
            var source = new Windows.Media.Capture.MediaCapture();

            try
            {
                //Use a specific camera
                var cameraId = await FindRearFacingCamera();

                if (!string.IsNullOrEmpty(cameraId))
                {
                    var settings = new MediaCaptureInitializationSettings();
                    settings.VideoDeviceId        = cameraId;
                    settings.StreamingCaptureMode = StreamingCaptureMode.Video;

                    await source.InitializeAsync(settings);

                    PreviewScreen.Source = source;

                    //Start video preview
                    await source.StartPreviewAsync();
                }
            }
            catch
            {
            }
        }
        /// <summary>
        /// This is the click handler for the 'StartPreview' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void StartPreview_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Check if the machine has a webcam
                DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
                if (devices.Count > 0)
                {
                    rootPage.NotifyUser("", NotifyType.ErrorMessage);

                    if (mediaCaptureMgr == null)
                    {
                        // Using Windows.Media.Capture.MediaCapture APIs to stream from webcam
                        mediaCaptureMgr = new MediaCapture();
                        await mediaCaptureMgr.InitializeAsync();

                        VideoStream.Source = mediaCaptureMgr;
                        await mediaCaptureMgr.StartPreviewAsync();
                        previewStarted = true;

                        ShowSettings.Visibility = Visibility.Visible;
                        StartPreview.IsEnabled = false;
                    }
                }
                else
                {
                    rootPage.NotifyUser("A webcam is required to run this sample.", NotifyType.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                mediaCaptureMgr = null;
                rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage);
            }
        }
        private async Task Initialize()
        {
            captureManager = new MediaCapture();

            await captureManager.InitializeAsync();
            capturePreview.Source = captureManager;
            await captureManager.StartPreviewAsync();
        }
        async private void IniciaPreviaCapturaFoto(object sender, RoutedEventArgs e)
        {
            GerenteCaptura = new Windows.Media.Capture.MediaCapture();
            await GerenteCaptura.InitializeAsync();

            GerenteCaptura.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
            CapturaPrevia.Source = GerenteCaptura;
            await GerenteCaptura.StartPreviewAsync();
        }
 private async Task Init()
 {
     MC = new MediaCapture();
     var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
     var camera = cameras.First();
     var settings = new MediaCaptureInitializationSettings() { VideoDeviceId = camera.Id };
     await MC.InitializeAsync(settings);
     ViewFinder.Source = MC;
     await MC.StartPreviewAsync();
 }
        async void InitCapture()
        {
            captureMgr = new Windows.Media.Capture.MediaCapture();

            await captureMgr.InitializeAsync();

            capturePreview.Source = captureMgr;

            await captureMgr.StartPreviewAsync();
        }
        private async void profilePicture_Tapped(object sender, TappedRoutedEventArgs e)
        {
            mediaCapture = new MediaCapture();
            await mediaCapture.InitializeAsync();

            stackPreview.Visibility = Visibility.Visible;
            previewElement.Source = mediaCapture;

            await mediaCapture.StartPreviewAsync();
        }
 async void InitCamera()
 {
     mc = new MediaCapture();
     var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
     var camera = cameras[1];
     var settings = new MediaCaptureInitializationSettings() { VideoDeviceId = camera.Id };
     await mc.InitializeAsync(settings);
     ce.Source = mc;
     await mc.StartPreviewAsync();
 }
		async void MainPage_Loaded(object sender, RoutedEventArgs e)
		{
			mediaCapture = new MediaCapture();
			await mediaCapture.InitializeAsync();

			CaptureElement.Source = mediaCapture;
			await mediaCapture.StartPreviewAsync();
			urhoApp = UrhoSurface.Run<UrhoApp>();
			urhoApp.CaptureVideo(CaptureFrameAsync);
		}
Exemple #21
0
        private async void InitializeCamera()
        {
            if (captureManager == null)
            {
                captureManager = new MediaCapture();
                await captureManager.InitializeAsync();

                PhotoCaptureElement.Source = captureManager;
                await captureManager.StartPreviewAsync();
            }
        }
        async void RecordAndRotate(MediaCapture captureMgr)
        {
            captureMgr = new MediaCapture();
            await captureMgr.InitializeAsync();

            // <SnippetCaptureRotateSetRecordRotate>
            //captureMgr.SetRecordRotation(VideoRotation.Clockwise90Degrees);
            // </SnippetCaptureRotateSetRecordRotate>

            capturePreview.Source = captureMgr;
            await captureMgr.StartPreviewAsync();
        }
Exemple #23
0
        private async Task<bool> InitMediaCapture()
        {
            _captureManager = new MediaCapture();
            await _captureManager.InitializeAsync();

            captureElement.Source = _captureManager;
            captureElement.FlowDirection = FlowDirection.RightToLeft;

            // start capture preview
            await _captureManager.StartPreviewAsync();

            return true;
        }
Exemple #24
0
        // Start the Video Capture
        private async void StartMediaCaptureSession()
        {
            var storageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync("cameraCapture.wmv", Windows.Storage.CreationCollisionOption.GenerateUniqueName);

            fileName = storageFile.Name;

            await mediaCapture.StartRecordToStorageFileAsync(profile, storageFile);

            recording = true;

            // start the preview
            capturePreview.Source = mediaCapture;
            await mediaCapture.StartPreviewAsync();
        }
        private async void InitializeCamera()
        {
            var videoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
            var rearCamera = videoDevices.First(item => item.EnclosureLocation != null &&
                                                        item.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
            _captureManager = new MediaCapture();

            await _captureManager.InitializeAsync(new MediaCaptureInitializationSettings
            {
                VideoDeviceId = rearCamera.Id
            });

            capturePreview.Source = _captureManager;
            await _captureManager.StartPreviewAsync();
        }
        public async Task InitializeAsync()
        {
            // Discover all the cameras
            await EnumerateCamerasAsync();

            // Create a camera preview image source (from Imaging SDK)
            captureManager = new MediaCapture();
            MediaCaptureInitializationSettings captureSettings = new MediaCaptureInitializationSettings();
            captureSettings.VideoDeviceId = backCamera.Id;

            await captureManager.InitializeAsync(captureSettings);

            CameraPreview.Source = captureManager;
            captureManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
            await captureManager.StartPreviewAsync();
        }
        private async void FaceComp_Loaded(object sender, RoutedEventArgs e)
        {
            var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Back);
            takePhotoManager = new MediaCapture();

            await takePhotoManager.InitializeAsync(new MediaCaptureInitializationSettings
            {
                StreamingCaptureMode = StreamingCaptureMode.Video,
                //PhotoCaptureSource = PhotoCaptureSource.Photo,
                AudioDeviceId = string.Empty,
                VideoDeviceId = cameraID.Id
            });

            await takePhotoManager.ClearEffectsAsync(MediaStreamType.Photo);
            PhotoPreview.Source = takePhotoManager;
            await takePhotoManager.StartPreviewAsync();
        }
Exemple #28
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            // Create new MediaCapture 
            MyMediaCapture = new MediaCapture();
            await MyMediaCapture.InitializeAsync();

            // Assign to Xaml CaptureElement.Source and start preview
            myCaptureElement.Source = MyMediaCapture;

            // show preview
            await MyMediaCapture.StartPreviewAsync();

            

            

        }
        async private void IniciaPreviaCapturaFoto(object sender, RoutedEventArgs e)
        {
            GerenteCaptura = new Windows.Media.Capture.MediaCapture();
            var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Front);

            await GerenteCaptura.InitializeAsync(new MediaCaptureInitializationSettings
            {
                StreamingCaptureMode = StreamingCaptureMode.Video,
                PhotoCaptureSource = PhotoCaptureSource.Photo,
                AudioDeviceId = string.Empty,
                VideoDeviceId = cameraID.Id,
            });

            GerenteCaptura.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
            CapturaPrevia.Source = GerenteCaptura;
            await GerenteCaptura.StartPreviewAsync();
        }
        public async void startPreview()
        {
            _mediaCapture = new Windows.Media.Capture.MediaCapture();
            (App.Current as App).MediaCapture = _mediaCapture;

            await _mediaCapture.InitializeAsync();

            CreateProfile();

            TurnMirroringOn();

            // <SnippetMediaCaptureVideo_StartPreview>
            // Start Previewing
            await _mediaCapture.StartPreviewAsync();

            (App.Current as App).IsPreviewing = true;
            // </SnippetMediaCaptureVideo_StartPreview>
        }
        /// <summary>
        /// Initializes the MediaCapture, starts preview.
        /// </summary>
        public async Task InitializeCameraAsync()
        {
            MediaCapture = new MediaCapture();
            MediaCapture.Failed += MediaCapture_Failed;

            try
            {
                await MediaCapture.InitializeAsync();
                _previewControl.Source = MediaCapture;
                await MediaCapture.StartPreviewAsync();
                IsPreviewing = true;
            }
            catch (UnauthorizedAccessException)
            {
                // This can happen if access to the camera has been revoked.
                MainPage.Current.NotifyUser("The app was denied access to the camera", NotifyType.ErrorMessage);
                await CleanupCameraAsync();
            }
        }
Exemple #32
0
        private async Task CaptureImage()
        {
            // Capture a new photo or video from the device.
            cameraCapture = new MediaCapture();
            cameraCapture.Failed += cameraCapture_Failed;

            // Initialize the camera for capture.
            await cameraCapture.InitializeAsync();

            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Media.Capture.CameraOptionsUI"))
            {
                CameraOptionsUI.Show(cameraCapture);
            }
            
            captureGrid.Visibility = Windows.UI.Xaml.Visibility.Visible;
            previewElement.Visibility = Windows.UI.Xaml.Visibility.Visible;
            previewElement.Source = cameraCapture;
            await cameraCapture.StartPreviewAsync();
        }
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            // TODO: Prepare page for display here.

            // TODO: If your application contains multiple pages, ensure that you are
            // handling the hardware Back button by registering for the
            // Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
            // If you are using the NavigationHelper provided by some templates,
            // this event is handled for you.

            // Create MediaCapture and init
            mediaCapture = new MediaCapture();
            await mediaCapture.InitializeAsync();
            mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
            

            // Assign to Xaml CaptureElement.Source and start preview
            capturePreview.Source = mediaCapture;
            await mediaCapture.StartPreviewAsync();
        }
Exemple #34
0
        private async Task <MediaCapture> ConnectToCamera(int i, CaptureElement preview)
        {
            var manager = new Windows.Media.Capture.MediaCapture();

            var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            if (allVideoDevices.Count > i)
            {
                var cameraDevice = allVideoDevices[i];

                await manager.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id, StreamingCaptureMode = StreamingCaptureMode.Video });

                var cameraProperties = manager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Select(x => x as VideoEncodingProperties).ToList();
                foreach (var mediaEncodingProperty in cameraProperties)
                {
                    Debug.WriteLine(mediaEncodingProperty.Width + "x" + mediaEncodingProperty.Height + " FPS: " + mediaEncodingProperty.FrameRate.Numerator + "Type:" + mediaEncodingProperty.Type + "   SubType:" + mediaEncodingProperty.Subtype);
                }


                foreach (var mediaEncodingProperty in cameraProperties)
                {
                    if (//mediaEncodingProperty.Width == 960 &&
                        //mediaEncodingProperty.Height == 544 &&
                        mediaEncodingProperty.Width == 320 &&
                        mediaEncodingProperty.Height == 240 &&
                        mediaEncodingProperty.FrameRate.Numerator == 15 &&
                        string.Compare(mediaEncodingProperty.Subtype, "YUY2") == 0)
                    {
                        Debug.WriteLine("Chosen: " + mediaEncodingProperty.Width + "x" + mediaEncodingProperty.Height + " FPS: " + mediaEncodingProperty.FrameRate.Numerator + "Type:" + mediaEncodingProperty.Type + "   SubType:" + mediaEncodingProperty.Subtype);
                        await manager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, mediaEncodingProperty);

                        break;
                    }
                }

                preview.Source = manager;
                await manager.StartPreviewAsync();
            }

            return(manager);
        }
        private async void CaptureImage(object parameter)
        {
            try
            {
                MediaCaptureManager = new Windows.Media.Capture.MediaCapture();
                await MediaCaptureManager.InitializeAsync();

                MediaCaptureManager.Failed += MediaCaptureManager_Failed;
                this._previewElement.Source = MediaCaptureManager;

                await MediaCaptureManager.StartPreviewAsync();

                this.PreviewEnabled = true;
                this.Idle           = true;
                SetupVideoPreviewSettings();
            }
            catch (Exception ex)
            {
                ShowFatalErrorMessageDialog(ex.Message, string.Empty);
            }
        }
        async public void initPhotoControl()
        {
            setMediaCaptureInitializationSettings();
            // reset all properties if photoManager contains an object.
            if (_captureManager != null)
            {
                _captureManager.Dispose();
                _captureManager = null;
            }
            _captureManager = new MediaCapture();
            await _captureManager.InitializeAsync(getMediaCaptureInitializationSettings());

            cptElementShowPreview.Source = _captureManager;

            await _captureManager.StartPreviewAsync();

            DisplayInformation displayInfo = DisplayInformation.GetForCurrentView();

            displayInfo.OrientationChanged += DisplayInfo_OrientationChanged;

            DisplayInfo_OrientationChanged(displayInfo, null);
        }
        internal async void btnStartPreview_Click(Object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            m_bPreviewing = false;
            try
            {
                ShowStatusMessage("Starting preview");
                EnableButton(false, "StartPreview");

                previewCanvas2.Visibility = Windows.UI.Xaml.Visibility.Visible;
                previewElement2.Source    = m_mediaCaptureMgr;
                await m_mediaCaptureMgr.StartPreviewAsync();

                m_bPreviewing = true;
                ShowStatusMessage("Start preview successful");
            }
            catch (Exception exception)
            {
                m_bPreviewing          = false;
                previewElement2.Source = null;
                EnableButton(true, "StartPreview");
                ShowExceptionMessage(exception);
            }
        }
        private async void v_Button_Capture_Click(object sender, RoutedEventArgs e)
        {
            isCapturing = !isCapturing;

            if (isCapturing)
            {
                if (isFirst)
                {
                    captureManager = new MediaCapture();

                    await captureManager.InitializeAsync();

                    capturePreview.Source = captureManager;
                    await captureManager.StartPreviewAsync();

                    isFirst = false;
                }
                v_Image.Source = null;
            }
            else
            {
                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();

                var stream = new InMemoryRandomAccessStream();

                await captureManager.CapturePhotoToStreamAsync(imageProperties, stream);

                _bitmap = new WriteableBitmap(300, 300);
                stream.Seek(0);
                await _bitmap.SetSourceAsync(stream);

                //await captureManager.StopPreviewAsync();

                v_Image.Source = _bitmap;
            }
        }
        private async void btnStartPreview_Click(Object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            try
            {
                ShowStatusMessage("Starting preview");
                btnStartPreview4.IsEnabled          = false;
                btnStartStopPhotoSequence.IsEnabled = true;
                m_bPreviewing = true;

                previewCanvas4.Visibility = Windows.UI.Xaml.Visibility.Visible;
                previewElement4.Source    = m_capture;
                await m_capture.StartPreviewAsync();

                ShowStatusMessage("Start preview successful");
            }
            catch (Exception ex)
            {
                previewElement4.Source              = null;
                btnStartPreview4.IsEnabled          = true;
                btnStartStopPhotoSequence.IsEnabled = false;
                m_bPreviewing = false;
                ShowExceptionMessage(ex);
            }
        }
Exemple #40
0
        private async Task InitializeQrCode()
        {
            // Find all available webcams
            DeviceInformationCollection webcamList = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            // Get the proper webcam (default one)
            DeviceInformation backWebcam = (from webcam in webcamList
                                            where webcam.IsEnabled
                                            select webcam).FirstOrDefault();

            // Initializing MediaCapture
            _mediaCapture = new MediaCapture();
            await _mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
            {
                VideoDeviceId = backWebcam.Id,
                AudioDeviceId = "",
                StreamingCaptureMode = StreamingCaptureMode.Video,
                PhotoCaptureSource = PhotoCaptureSource.VideoPreview
            });

            // Set the source of CaptureElement to MediaCapture
            captureElement.Source = _mediaCapture;
            await _mediaCapture.StartPreviewAsync();
        }
        public async Task StartScanningAsync(Action<ZXing.Result> scanCallback, MobileBarcodeScanningOptions options = null)
        {
            if (stopping)
                return;

            isAnalyzing = true;
            ScanCallback = scanCallback;
            ScanningOptions = options ?? MobileBarcodeScanningOptions.Default;

            topText.Text = TopText ?? string.Empty;
            bottomText.Text = BottomText ?? string.Empty;

            if (UseCustomOverlay)
            {
                gridCustomOverlay.Children.Clear();
                if (CustomOverlay != null)
                    gridCustomOverlay.Children.Add(CustomOverlay);

                gridCustomOverlay.Visibility = Visibility.Visible;
                gridDefaultOverlay.Visibility = Visibility.Collapsed;
            }
            else
            {
                gridCustomOverlay.Visibility = Visibility.Collapsed;
                gridDefaultOverlay.Visibility = Visibility.Visible;
            }

            // Find which device to use
            var preferredCamera = await this.GetFilteredCameraOrDefaultAsync(ScanningOptions);            
            mediaCapture = new MediaCapture();
            
            // Initialize the capture with the settings above
            await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings()
            {
                StreamingCaptureMode = StreamingCaptureMode.Video,
                VideoDeviceId = preferredCamera.Id
            });

            // Set the capture element's source to show it in the UI
            captureElement.Source = mediaCapture;

            // Start the preview
            await mediaCapture.StartPreviewAsync();
            
            // Get all the available resolutions for preview
            var availableProperties = mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview);
            var availableResolutions = new List<CameraResolution>();
            foreach (var ap in availableProperties)
            {
                var vp = (VideoEncodingProperties)ap;
                System.Diagnostics.Debug.WriteLine("Camera Preview Resolution: {0}x{1}", vp.Width, vp.Height);
                availableResolutions.Add(new CameraResolution { Width = (int)vp.Width, Height = (int)vp.Height });                
            }
            CameraResolution previewResolution = null;
            if (ScanningOptions.CameraResolutionSelector != null)
                previewResolution = ScanningOptions.CameraResolutionSelector(availableResolutions);

            // If the user did not specify a resolution, let's try and find a suitable one
            if (previewResolution == null)
            {
                // Loop through all supported sizes
                foreach (var sps in availableResolutions)
                {
                    // Find one that's >= 640x360 but <= 1000x1000
                    // This will likely pick the *smallest* size in that range, which should be fine
                    if (sps.Width >= 640 && sps.Width <= 1000 && sps.Height >= 360 && sps.Height <= 1000)
                    {
                        previewResolution = new CameraResolution
                        {
                            Width = sps.Width,
                            Height = sps.Height
                        };
                        break;
                    }
                }
            }

            if (previewResolution == null)
                previewResolution = availableResolutions.LastOrDefault();

            System.Diagnostics.Debug.WriteLine("Using Preview Resolution: {0}x{1}", previewResolution.Width, previewResolution.Height);

            // Find the matching property based on the selection, again
            var chosenProp = availableProperties.FirstOrDefault(ap => ((VideoEncodingProperties)ap).Width == previewResolution.Width && ((VideoEncodingProperties)ap).Height == previewResolution.Height);
            
            // Set the selected resolution
            await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, chosenProp);

            await SetPreviewRotationAsync();

            captureElement.Stretch = Stretch.UniformToFill;

            // Get our preview properties
            var previewProperties = mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;
            
            // Setup a frame to use as the input settings
            var destFrame = new VideoFrame(Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, (int)previewProperties.Width, (int)previewProperties.Height);

            var zxing = ScanningOptions.BuildBarcodeReader();

            timerPreview = new Timer(async (state) => {
                if (stopping)
                    return;                               
                if (mediaCapture == null || mediaCapture.CameraStreamState != Windows.Media.Devices.CameraStreamState.Streaming)
                    return;
                if (processing)
                    return;
                if (!isAnalyzing)
                    return;

                processing = true;

                SoftwareBitmapLuminanceSource luminanceSource = null;

                try
                {

                    // Get preview 
                    var frame = await mediaCapture.GetPreviewFrameAsync(destFrame);

                    // Create our luminance source
                    luminanceSource = new SoftwareBitmapLuminanceSource(frame.SoftwareBitmap);

                } catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("GetPreviewFrame Failed: {0}", ex);
                }

                ZXing.Result result = null;

                try
                {
                    // Try decoding the image
                    if (luminanceSource != null)
                        result = zxing.Decode(luminanceSource);
                }
                catch (Exception ex)
                {
                    
                }

                // Check if a result was found
                if (result != null && !string.IsNullOrEmpty (result.Text))
                {
                    if (!ContinuousScanning)
                        await StopScanningAsync();
                    LastScanResult = result;
                    ScanCallback(result);                    
                }

                processing = false;
                         
            }, null, TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));           
        }
        private async Task CreateMediaCapture()
        {
            mediaCapture = new MediaCapture();
            mediaCapture.Failed += mediaCapture_Failed;

            var settings = new MediaCaptureInitializationSettings()
            {
                StreamingCaptureMode = StreamingCaptureMode.Video
            };

            try
            {
                await mediaCapture.InitializeAsync(settings);
            }
            catch (Exception)
            {
                this.progressText.Text = "No camera is available.";
                return;
            }

            captureElement.Source = mediaCapture;
            await mediaCapture.StartPreviewAsync();
        }
        //private void orientView()
        //{
        //    var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
        //    grid.Height = bounds.Height;
        //    grid.Width = bounds.Width;

        //    var displayInfo = Windows.Graphics.Display.DisplayInformation.GetForCurrentView();
        //    switch (displayInfo.CurrentOrientation)
        //    {
        //        case Windows.Graphics.Display.DisplayOrientations.Landscape:
        //            mediaCapture.SetPreviewRotation(VideoRotation.None);
        //            break;
        //        case Windows.Graphics.Display.DisplayOrientations.LandscapeFlipped:
        //            mediaCapture.SetPreviewRotation(VideoRotation.Clockwise180Degrees);
        //            break;
        //        case Windows.Graphics.Display.DisplayOrientations.Portrait:
        //            mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
        //            break;
        //        case Windows.Graphics.Display.DisplayOrientations.PortraitFlipped:
        //            mediaCapture.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
        //            break;
        //    }
        //}

        async private void InitCamera()
        {
            if (App.APP_SETTINGS.Cameras.Count > 0)
            {
                try
                {
                    mediaCapture = new MediaCapture();
                    await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = App.APP_SETTINGS.Cameras[App.APP_SETTINGS.SelectedCamera].ID, PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.VideoPreview, StreamingCaptureMode = StreamingCaptureMode.Video });
                    SetResolution();

                    capturePreview.Source = mediaCapture;
                    //orientView();

                    if(App.IsMobile)
                        mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);

                    await mediaCapture.StartPreviewAsync();
                    if (mediaCapture.VideoDeviceController.FocusControl.Supported)
                    {
                        await mediaCapture.VideoDeviceController.FocusControl.SetPresetAsync(Windows.Media.Devices.FocusPreset.AutoNormal);
                    }
                    else
                    {
                        FocusText.Visibility = Visibility.Collapsed;
                    }
             
                    if(!mediaCapture.VideoDeviceController.TorchControl.Supported)
                    {
                        btnTorch.Visibility = Visibility.Collapsed;
                    }
                    
                    beginCapture();
                }
                catch (Exception ex)
                {

                }
            }
            else
            {
                NoCamera.Visibility = Visibility.Visible;
            }
        }
Exemple #44
0
 async private void StartCapturePreview_Click(object sender, RoutedEventArgs e)
 {
     capturePreview.Source = captureManager;
     await captureManager.StartPreviewAsync();
 }
Exemple #45
0
        internal async void button1_Click(object sender, RoutedEventArgs e)
        {
            /* Way one to use camera -> Full screen mode*/
            /* CameraCapture(); */
            /* Way two CaptureElement and canvas */

            try
            {
                button1.IsEnabled = false;
                //ShowStatusMessage("Starting device");
                m_mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
                await m_mediaCaptureMgr.InitializeAsync();

                if (m_mediaCaptureMgr.MediaCaptureSettings.VideoDeviceId != "" && m_mediaCaptureMgr.MediaCaptureSettings.AudioDeviceId != "")
                {
                    canpreview   = true;
                    canrecord    = true;
                    cantakephoto = true;

                    //ShowStatusMessage("Device initialized successful");

                    m_mediaCaptureMgr.RecordLimitationExceeded += new Windows.Media.Capture.RecordLimitationExceededEventHandler(RecordLimitationExceeded);
                    m_mediaCaptureMgr.Failed += new Windows.Media.Capture.MediaCaptureFailedEventHandler(Failed);
                }
                else
                {
                    button1.IsEnabled = true;
                    //ShowStatusMessage("No VideoDevice/AudioDevice Found");
                }
            }
            catch (Exception exception)
            {
                //ShowExceptionMessage(exception);
            }

            /* So far the code was for starting the device*/

            /* Now the code to preview the image */

            m_bPreviewing = false;
            try
            {
                //ShowStatusMessage("Starting preview");
                button1.IsEnabled = false;
                canpreview        = false;

                previewCanvas1.Visibility = Windows.UI.Xaml.Visibility.Visible;
                previewElement1.Source    = m_mediaCaptureMgr;
                await m_mediaCaptureMgr.StartPreviewAsync();

                if ((m_mediaCaptureMgr.VideoDeviceController.Brightness != null) && m_mediaCaptureMgr.VideoDeviceController.Brightness.Capabilities.Supported)
                {
                    SetupVideoDeviceControl(m_mediaCaptureMgr.VideoDeviceController.Brightness, sldBrightness);
                }
                if ((m_mediaCaptureMgr.VideoDeviceController.Contrast != null) && m_mediaCaptureMgr.VideoDeviceController.Contrast.Capabilities.Supported)
                {
                    SetupVideoDeviceControl(m_mediaCaptureMgr.VideoDeviceController.Contrast, sldContrast);
                }
                rect1.Visibility = Visibility.Visible;
                m_bPreviewing    = true;
                //ShowStatusMessage("Start preview successful");

                captureclr.IsEnabled = true;
            }
            catch (Exception exception)
            {
                m_bPreviewing          = false;
                previewElement1.Source = null;
                /* If attempt to get preview fails he can try again */
                button1.IsEnabled = true;
                canpreview        = true;
                //ShowExceptionMessage(exception);
            }
        }