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 桌面应用程序 - 无法正常工作
基础教程推荐
- MS Visual Studio .NET 的替代品 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01