以下代码不起作用
The following code doesnt work
我从这里复制了以下代码:
https://code.msdn.microsoft.com/windowsapps/WindowsPhone-Store-81-vs-25c80c2a#content
MediaCapture captureManager;
async private void InitCamera_Click(object sender, RoutedEventArgs e)
{
captureManager = new MediaCapture();
await captureManager.InitializeAsync();
}
async private void StartCapturePreview_Click(object sender, RoutedEventArgs e)
{
capturePreview.Source = captureManager;
await captureManager.StartPreviewAsync();
}
async private void StopCapturePreview_Click(object sender, RoutedEventArgs e)
{
await captureManager.StopPreviewAsync();
}
async private void CapturePhoto_Click(object sender, RoutedEventArgs e)
{
ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
// create storage file in local app storage
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(
"TestPhoto.jpg",
CreationCollisionOption.GenerateUniqueName);
// take photo
await captureManager.CapturePhotoToStorageFileAsync(imgFormat, file);
// Get photo as a BitmapImage
BitmapImage bmpImage = new BitmapImage(new Uri(file.Path));
// imagePreivew is a <Image> object defined in XAML
imagePreview.Source = bmpImage;
}
当我尝试 运行 时,它没有定义 capturePreview。我删除了该行,但出现两个异常:
Exception thrown: 'System.ArgumentException' in mscorlib.ni.dll
Exception thrown: 'System.ArgumentException' in mscorlib.ni.dll
你知道问题所在吗?
Windows phone 8.1 RT 应用程序
编辑:同样的代码也可以在这里找到:https://msdn.microsoft.com/en-us/library/windows.media.capture.mediacapture.aspx?f=255&MSPPError=-2147217396
我在另一个页面中遇到异常,当我调用此框架时出现异常,这与实际代码无关。
我从这里复制了以下代码: https://code.msdn.microsoft.com/windowsapps/WindowsPhone-Store-81-vs-25c80c2a#content
MediaCapture captureManager;
async private void InitCamera_Click(object sender, RoutedEventArgs e)
{
captureManager = new MediaCapture();
await captureManager.InitializeAsync();
}
async private void StartCapturePreview_Click(object sender, RoutedEventArgs e)
{
capturePreview.Source = captureManager;
await captureManager.StartPreviewAsync();
}
async private void StopCapturePreview_Click(object sender, RoutedEventArgs e)
{
await captureManager.StopPreviewAsync();
}
async private void CapturePhoto_Click(object sender, RoutedEventArgs e)
{
ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
// create storage file in local app storage
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(
"TestPhoto.jpg",
CreationCollisionOption.GenerateUniqueName);
// take photo
await captureManager.CapturePhotoToStorageFileAsync(imgFormat, file);
// Get photo as a BitmapImage
BitmapImage bmpImage = new BitmapImage(new Uri(file.Path));
// imagePreivew is a <Image> object defined in XAML
imagePreview.Source = bmpImage;
}
当我尝试 运行 时,它没有定义 capturePreview。我删除了该行,但出现两个异常:
Exception thrown: 'System.ArgumentException' in mscorlib.ni.dll
Exception thrown: 'System.ArgumentException' in mscorlib.ni.dll
你知道问题所在吗? Windows phone 8.1 RT 应用程序
编辑:同样的代码也可以在这里找到:https://msdn.microsoft.com/en-us/library/windows.media.capture.mediacapture.aspx?f=255&MSPPError=-2147217396
我在另一个页面中遇到异常,当我调用此框架时出现异常,这与实际代码无关。