c# - 从 Windows Phone 8.1 WinRT 相机预览中捕获 WriteableBitmap

标签 c# camera windows-runtime windows-phone-8.1

我的问题是这样的。如何从 WP 8.1 WinRT 中的相机预览图像获取 WriteableBitmap?

我以前在 silverlight 中做过这个,但我似乎无法在 WinRT 中完成...

我的目标是扫描相机预览图像中的条形码。我不想拍照并从那里扫描条形码。我想从相机预览中扫描条形码。

我这样初始化我的相机:

// First get the rear camera
var _rearCamera = await GetCameraDeviceInfoAsync(Windows.Devices.Enumeration.Panel.Back);

_mediaCapture = new MediaCapture();
// Set up the initialization settings to use rear camera
await _mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
{
    StreamingCaptureMode = StreamingCaptureMode.Video,
    PhotoCaptureSource = PhotoCaptureSource.VideoPreview,
    AudioDeviceId = string.Empty,
    VideoDeviceId = _rearCamera.Id
});

然后我设置预览并开始在 previewElement 上显示它。

// Find the supported preview size that's closest to the desired size
var availableMediaStreamProperties =
    _mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview)
        .OfType<VideoEncodingProperties>()
        .Where(p => p != null && !String.IsNullOrEmpty(p.Subtype) && supportedVideoFormats.Contains(p.Subtype.ToLower()))
    .OrderByDescending(p => p.Width)
        .ToList();
_previewFormat = availableMediaStreamProperties.FirstOrDefault();

// Start Preview stream
await _mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, _previewFormat);

_mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
previewElement.Source = _mediaCapture;
await _mediaCapture.StartPreviewAsync();

但现在我需要以某种方式在 PreviewElement 上获取相机图像的快照,以便我可以将其发送到 ZXing 进行条形码解码。

我看了无数的示例,但大多数都是针对 WP 8.0 或 WP 8.1 Silverlight 的...

如有任何帮助,我们将不胜感激。

最佳答案

要截取直播流,您需要编写 Media Foundation Transform (MFT) 在 C++ 中作为 media extension 插入渲染管道.

Media extensions sample演示编写这样的媒体扩展。另见 Walkthrough: Creating a Windows Store app using WRL and Media Foundation

一旦你有了框架,你应该能够将它传递给 zxing 进行处理。

关于c# - 从 Windows Phone 8.1 WinRT 相机预览中捕获 WriteableBitmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28775238/

相关文章:

java - Google Mirror API 中的相机访问

Android - 使用相机 Intent (ACTION_VIDEO_CAPTURE) 显示不同的方向

c++ - 您如何在控制台中测试C + WinRT组件?

c# - 如何动态调整 GridView 项目的大小?

c# - 在 C# 中使用 FtpWebRequest 和 BackgroundWorker 递归上传文件

c# - DataTemplate 多个数据触发相同的元素和属性

c# - 如果 Observable 的订阅者需要触发 OnNext() 怎么办?

c# - 清除控件后,我应该如何停止控件中的计时器?

ios - 如何自定义相机 View 并捕获叠加中的部分?

Windows 8 MDM - 公司应用