0

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.

David Božjak
  • 16,887
  • 18
  • 67
  • 98
jalgames
  • 781
  • 4
  • 23
  • What is the size of your image? The error might also happen as a result of running out of memory. Do not rely on the contents of the `Bitmap` constructor's exceptions. Any exception there just means _anything_ went wrong. – PMF Mar 23 '14 at 13:59
  • Even if I set the resoultion to the lowest possible capture resolution (640x480), it crashes with the same exception. – jalgames Mar 23 '14 at 14:02
  • No idea :-( But if I see how "exhaustive" the documentation on this api is ( http://developer.nokia.com/resources/library/Imaging_API_Ref/nokiagraphicsimaging-namespace/bitmap-class/bitmap-constructor/bitmap-constructor-size-colormode-uint32-ibuffer.html ) I'll ask myself twice whether I'll use it. – PMF Mar 23 '14 at 14:58
  • Is that the actual size you pass in? You will also get an exception if the size you pass in is Size(0, 0). – David Božjak Mar 24 '14 at 08:36
  • And are you sure you sure the content in the IBuffer is actually BGRA888? – David Božjak Mar 24 '14 at 08:39
  • Basically debugging this would be a lot easier if you could tell us what exactly you are passing into the constructor. Thanks! – David Božjak Mar 24 '14 at 09:00

0 Answers0