My problem is this. How can I get a WriteableBitmap from the camera preview image in WP 8.1 WinRT?
I have done this in silverlight before, but i just can't seem to get it done in WinRT...
My goal is to scan for barcode in the camera preview image. I don't want to take a picture and scan for the barcode from there. I want to scan for the barcode from the camera preview.
I initialize my camera like this:
// 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
});
Then i setup the preview and start displaying it on the 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();
But now i would need to somehow get a snapshot of the camera image on PreviewElement so i can send it to ZXing for barcode decoding.
I have looked at countless number of samples, but most of them are for WP 8.0 or WP 8.1 Silverlight...
Any help would be appreciated.