从 Windows Phone 捕获 WriteableBitmap 8.1 WinRT 相机预览

Capture WriteableBitmap from Windows Phone 8.1 WinRT Camera preview

我的问题是这样的。如何从 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) in C++ to plug into the rendering pipeline as a media extension.

Media extensions sample demonstrates writing such a media extension. Also see Walkthrough: Creating a Windows Store app using WRL and Media Foundation

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

在研究了 Lumia Imaging SDK 之后...我找到了 Real-time Filter Demo for Windows and Windows 8.1 的示例,它用非常简单的代码完全满足了我的需要。

并且要控制相机并进行对焦,例如我可以简单地:

VideoDeviceController vdc = (VideoDeviceController)_cameraPreviewImageSource.VideoDeviceController;
await vdc.FocusControl.FocusAsync();