MediaCapture Windows 8 Desktop Application- Can#39;t get it work(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 桌面应用程序 - 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MediaCapture Windows 8 桌面应用程序 - 无法正常工作


- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01