In a filter app I'm working on I want to add the ability to capture images and apply filters to them by using the Nokia Imaging SDK 1.1. Searching the internet for capturing code, I got this:
await _cameraEffect.PhotoCaptureDevice.SetCaptureResolutionAsync(PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).First());
await _cameraEffect.PhotoCaptureDevice.FocusAsync();
CameraCaptureSequence sequence = _cameraEffect.PhotoCaptureDevice.CreateCaptureSequence(1);
MemoryStream imageStream = new MemoryStream();
imageStream.Seek(0, SeekOrigin.Begin);
sequence.Frames[0].CaptureStream = imageStream.AsOutputStream();
await _cameraEffect.PhotoCaptureDevice.PrepareCaptureSequenceAsync(sequence);
await sequence.StartCaptureAsync();
_cameraEffect.PhotoCaptureDevice.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters,AutoFocusParameters.None);
imageStream.Seek(0, SeekOrigin.Begin);
IBuffer frameBuffer = imageStream.GetWindowsRuntimeBuffer();
var frameSize = new Windows.Foundation.Size(_cameraEffect.PhotoCaptureDevice.CaptureResolution.Width, _cameraEffect.PhotoCaptureDevice.CaptureResolution.Height);
var scanlineByteSize = (uint)frameSize.Width * 4;
var bitmap = new Bitmap(frameSize, ColorMode.Bgra8888, scanlineByteSize, frameBuffer);
var renderer = new BitmapRenderer(new FilterEffect { Filters = _cameraEffect._filterEffect.Filters }, bitmap);
await renderer.RenderAsync();
But when I run this code, I get a "{System.ArgumentException: The parameter is incorrect.
at Nokia.Graphics.Imaging.Bitmap..ctor(Size size, ColorMode colorMode, UInt32 scanlineByteSize, IBuffer pixels) at RealtimeFilterDemo.MainPage.d_1b.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.AsyncMethodBuilderCore.b_0(Object state)}".
It is thrown at
var bitmap = new Bitmap(frameSize, ColorMode.Bgra8888, scanlineByteSize, frameBuffer);
Does that mean the frameBuffer is not valid? And if so, how do I fix this? I already found some blog posts covering that problem, but they concluded that they had to use
imageStream.Seek(0, SeekOrigin.Begin);
and I already added that without any changes in the error message.