在 Windows Phone 8.1 上使用 MediaCapture 时拍摄的照片是黑色的 [英] Captured photos are black when using MediaCapture on Windows Phone 8.1

查看:27
本文介绍了在 Windows Phone 8.1 上使用 MediaCapture 时拍摄的照片是黑色的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MediaCapture 捕捉照片并存储它们.它在模拟器中工作.但是当在真机(诺基亚 Lumia 530)上运行该应用程序时,拍摄的照片只是黑色的.它们具有正确的大小并且文件具有一定的字节长度,但是在显示照片时它是黑色的.请注意,我不使用 Silverlight,并且固定使用 MediaCapture.使用默认相机应用程序时,手机上的相机工作.该应用的清单包括图片库"和网络摄像头"功能.

I am using MediaCapture to capture photos and store them. It works in the emulator. But when running the app on a real phone (Nokia Lumia 530) the captured photos are just black. They have a correct size and the file has a certain byte length, but when displaying the photo it's black. Please note that I do not use Silverlight and am fixed on using MediaCapture. The camera on the phone works when using the default camera app. The App's manifest includes the capabilities "Pictures Library" and "Webcam".

有人知道哪里出了问题吗?

Does someone know what could be wrong?

这是我使用的测试代码:

Here is the test code I use:

using (var mediaCapture = new MediaCapture())
{
   await mediaCapture.InitializeAsync();

   ImageEncodingProperties imageFormat = ImageEncodingProperties.CreateJpeg();
   StorageFile photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync("TestPhoto.jpg", CreationCollisionOption.GenerateUniqueName);
   await mediaCapture.CapturePhotoToStorageFileAsync(imageFormat, photoFile);

   BitmapImage bitmap = new BitmapImage();
   using (var photoStream = await photoFile.OpenReadAsync())
   {
      bitmap.SetSource(photoStream);
   }
}

编辑

我找到了解决方案.如果我们有 CaptureElement,将正确捕获照片,将其源设置为 MediaCapture 对象,在拍照前调用 MediaCapture.StartPreviewAsync,拍照(使用 CapturePhotoToStorageFileAsync),最后调用 StopPreviewAsync.MediaCapture 似乎需要一个现有的(和显示的)预览才能捕获照片.奇怪的是,这没有记录在案,并且在没有预览的情况下使用 CapturePhotoToStorageFileAsync 不会引发异常.

I found a solution. The photo is captured correctly if we have a CaptureElement, set it's source to the MediaCapture object, invoke MediaCapture.StartPreviewAsync before taking the photo, take the photo (using CapturePhotoToStorageFileAsync) and finally invoke StopPreviewAsync. It seems that MediaCapture needs an existing (and displayed) preview to be able to capture photos. Strange that this is not documented and using CapturePhotoToStorageFileAsync without a preview does not throw an Exception.

推荐答案

如果我们有一个 CaptureElement,照片就被正确捕获,将其源设置为 MediaCapture 对象,在拍照前调用 MediaCapture.StartPreviewAsync,拍照(使用CapturePhotoToStorageFileAsync) 并最终调用 StopPreviewAsync.MediaCapture 似乎需要一个现有的(和显示的)预览才能捕获照片.奇怪的是,这没有记录在案,并且在没有预览的情况下使用 CapturePhotoToStorageFileAsync 不会引发异常.

The photo is captured correctly if we have a CaptureElement, set it's source to the MediaCapture object, invoke MediaCapture.StartPreviewAsync before taking the photo, take the photo (using CapturePhotoToStorageFileAsync) and finally invoke StopPreviewAsync. It seems that MediaCapture needs an existing (and displayed) preview to be able to capture photos. Strange that this is not documented and using CapturePhotoToStorageFileAsync without a preview does not throw an Exception.

这篇关于在 Windows Phone 8.1 上使用 MediaCapture 时拍摄的照片是黑色的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆