MediaCapture Windows 8 Desktop Application- Can't get it work

前端 未结 2 1679
终归单人心
终归单人心 2021-01-26 06:21

I\'m trying to implement an image capture via this API, and I need to implement in via desktop application.

The problem is that when I save the image into a file (with <

2条回答
  •  粉色の甜心
    2021-01-26 06:49

    In order for your store app to interact with the Camera there are actually two ways, a simple one, and an advanced one:

    • Either by using the provided user interface, which is a common UI used to capture Media and it save you the pain of handling the basic capture operations,
    • Or by interacting with the MediaCapture API yourself to gain complete control over the entire flow of operations.

    if you just want to take a picture or a video from the webcam, i suggest you use the first approach which mainly use the CameraCaptureUI API, but if you need complete control over the capturing operation, you need some lines of codes that interact with the MediaCapture APIs

    here a simple example using the CameraCaptureUI API :

    let say we have the following UI:

     
            

    and here the capture button click handler:

    private async void TakePicture_Click(object sender, RoutedEventArgs e)
        {
            var camera = new CameraCaptureUI();
            var image = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);
            if (image != null)
            {
                var stream = await image.OpenAsync(FileAccessMode.Read);
                var bitmap = new BitmapImage();
                bitmap.SetSource(stream);
                Picture.Source = bitmap;
            }
            else
            {
                (new MessageDialog("Something went wrong")).ShowAsync();                
            }
        }
    

    you need also to offer your app the permission to use the webcam by checking the Webcam capability in the App Manifest

    enter image description here

提交回复
热议问题