MediaCaptureWPF icon indicating copy to clipboard operation
MediaCaptureWPF copied to clipboard

Unable to see preview of camera on specific machine

Open cygmrugeshchhatbar opened this issue 7 years ago • 0 comments

I am not able to see preview of video device on specific machine. But I am able to get the resolutions and take the screenshot from the video device.

Below is the code snippet to show preview from selected video device.

**DeviceInformation selectedDevice = Devices.SelectedItem as DeviceInformation;

        if (preview != null)
        {
            await preview.StopAsync();
            Preview.Source = null;
            preview = null;
        }

        var settings = new MediaCaptureInitializationSettings();
        settings.AudioDeviceId = "";
        settings.VideoDeviceId = selectedDevice.Id;
        settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Video;
        capture = new MediaCapture();
        await capture.InitializeAsync();

        preview = new CapturePreview(capture);
        Preview.Source = preview;
        await preview.StartAsync();

        PopulateComboBox(MediaStreamType.Photo, Resolutions, true);**

Here is the code snippet to take screenshot.

**try { ImageEncodingProperties format = ImageEncodingProperties.CreatePng(); //generate file in local folder: StorageFile capturefile; StorageFolder folder = KnownFolders.SavedPictures; capturefile = await folder.CreateFileAsync("photo_" + DateTime.Now.Ticks.ToString() + ".png", CreationCollisionOption.ReplaceExisting); //take & save photo await capture.CapturePhotoToStorageFileAsync(format, capturefile); //show captured photo

            if (!Directory.Exists(@"C:\Exports\CameraCaptures\"))
            {
                Directory.CreateDirectory(@"C:\Exports\CameraCaptures\");
            }

            string filePath = @"C:\Exports\CameraCaptures\" + Path.GetFileName(capturefile.Path);
            File.Copy(capturefile.Path, filePath);

            BitmapImage img = new BitmapImage(new Uri(filePath, UriKind.RelativeOrAbsolute));
            Captured.Source = img;
            Captured.Visibility = Visibility.Visible;
            Preview.Visibility = Visibility.Collapsed;

            await capturefile.DeleteAsync(StorageDeleteOption.PermanentDelete);
        }
        catch (Exception ex)
        {
            LogHelper.WriteException(ex);
        }**

Please find configuration of the machine shown in the image.

image

cygmrugeshchhatbar avatar Jan 29 '18 13:01 cygmrugeshchhatbar