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 <
In order for your store app to interact with the Camera there are actually two ways, a simple one, and an advanced one:
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:
<StackPanel Orientation="Vertical">
<Button Click="TakePicture_Click" Content="Capture Photo" HorizontalAlignment="Stretch"/>
<Border BorderBrush="White" BorderThickness="3">
<Image x:Name="Picture" Height="700" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Border>
</StackPanel>
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
Getting MediaCapture
to preview the camera video in Desktop apps is not trivial. I wasn't sure all the pieces were there so I put together some code on GitHub to try it out and it seems to work ok.
https://github.com/mmaitre314/MediaCaptureWPF
One caveat: building the MediaCapture/WPF interop required some native code (C++/CLI), so the app needs to be built as either x86 or x64, but not AnyCPU.