Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to see preview of camera on specific machine #9

Open
cygmrugeshchhatbar opened this issue Jan 29, 2018 · 0 comments
Open

Unable to see preview of camera on specific machine #9

cygmrugeshchhatbar opened this issue Jan 29, 2018 · 0 comments

Comments

@cygmrugeshchhatbar
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant