MediaCapture Windows 8 桌面应用程序 - 无法正常工作 [英] MediaCapture Windows 8 Desktop Application- Can't get it work

查看:48
本文介绍了MediaCapture Windows 8 桌面应用程序 - 无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过此 API 实现图像捕获,我需要通过桌面应用程序实现.

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

问题是,当我将图像保存到文件中时(使用 CapturePhotoToStorageFileAsync),我得到一张深色图片(几乎是黑色),或者我得到零大小的文件.

The problem is that when I save the image into a file (with CapturePhotoToStorageFileAsync) I get a dark picture (almost black), or I get zero size file.

我的代码很简单:

MediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();

Windows.Storage.StorageFile photoStorageFile;
String PHOTO_FILE_NAME = "photo.jpg";
photoStorageFile = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(PHOTO_FILE_NAME, Windows.Storage.CreationCollisionOption.GenerateUniqueName);
ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoStorageFile);

我阅读了另一个关于它的帖子:在使用 MediaCapture 时拍摄的照片是黑色的Windows Phone 8.1

I read another thread about it: Captured photos are black when using MediaCapture on Windows Phone 8.1

问题是 MediaCapture.StartPreviewAsync 引发了异常请求的操作中发生了意外错误",我猜原因是我没有的 MediaElement(再次,桌面).

The problem is that MediaCapture.StartPreviewAsync raised an exception "An unexpected error has occured in the operation requested", and I guess the reason for that is the MediaElement which I don't have (again, desktop).

我也很高兴找到一个工作示例,当我搜索时,我没有找到任何在桌面应用程序上实现 MediaCapture 的真实示例,我看到了一篇文章但没有附加代码:http://blogs.msdn.com/b/eternalcoding/archive/2013/10/29/how-to-use-specific-winrt-api-from-desktop-apps-capturing-a-photo-using-your-webcam-into-a-wpf-app.aspx

I'll also glad to find a working example, when I searched, I didn't find any real sample to implement MediaCapture on desktop application, I saw an article but without attached code: http://blogs.msdn.com/b/eternalcoding/archive/2013/10/29/how-to-use-specific-winrt-api-from-desktop-apps-capturing-a-photo-using-your-webcam-into-a-wpf-app.aspx

我还发现其他人也问了一个样本,但没有真正的答案......

I also found that others also asked about a sample, but with no real answer...

我怎样才能得到一个工作样本?

How can I get a working sample for that?

推荐答案

MediaCapture 在桌面应用中预览摄像头视频并非易事.我不确定所有的部分都在那里,所以我在 GitHub 上整理了一些代码来尝试一下,它似乎工作正常.

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

一个警告:构建 MediaCapture/WPF 互操作需要一些本机代码 (C++/CLI),因此应用需要构建为 x86 或 x64,而不是 AnyCPU.

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.

这篇关于MediaCapture Windows 8 桌面应用程序 - 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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