我尝试使用Windows RT / XAML开发模型创建可以使用Windows Phone 8.1相机的应用。
当我尝试从MediaCapture类调用任何一个捕获方法时,我得到一个带有消息&#34的ArgumentException;参数不正确。"这是我的代码
private async Task Initialize()
{
if (!DesignMode.DesignModeEnabled)
{
await _mediaCaptureMgr.InitializeAsync();
ViewFinder.Source = _mediaCaptureMgr;
await _mediaCaptureMgr.StartPreviewAsync();
}
}
private async void ViewFinder_OnTapped(object sender, TappedRoutedEventArgs e)
{
ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
var stream = new InMemoryRandomAccessStream();
await _mediaCaptureMgr.CapturePhotoToStreamAsync(imageProperties, stream);
_bitmap = new WriteableBitmap((int) ViewFinder.ActualWidth, (int) ViewFinder.ActualHeight);
stream.Seek(0);
await _bitmap.SetSourceAsync(stream);
PreviewImage.Source = _bitmap;
PreviewElements.Visibility = Visibility.Visible;
ViewFinder.Visibility = Visibility.Collapsed;
Buttons.Visibility = Visibility.Visible;
Message.Visibility = Visibility.Collapsed;
stream.Seek(0);
var buffer = new global::Windows.Storage.Streams.Buffer((uint) stream.Size);
stream.ReadAsync(buffer, (uint) stream.Size, InputStreamOptions.None);
DataContext = buffer.ToArray();
if (PhotoCaptured != null)
PhotoCaptured(this, null);
}
在页面加载时调用initialize方法,并在点击xaml中的CaptureElement时调用viewfinder_ontapped。
上引发了错误await _mediaCaptureMgr.CapturePhotoToStreamAsync(imageProperties, stream);
我真的很奇怪的是,我下载了winrt xaml工具包http://winrtxamltoolkit.codeplex.com/的最新资源,并尝试使用类似代码的示例相机应用程序。它在MediaCapture.CapturePhotoToStorageFileAsync()上抛出相同的错误。任何人都可以帮我确定原因吗?