I'm working on an imaging app using the nokia imaging SDK 1.1. A task seeming fairly simple (let the user choose an image and apply some filters to it) currently blocks me, for 2 days now. I've written hundreds of lines and reviewd all the Nokia Dev Samples (which, most of the time, are very well-strcutured, but too complex for an imaging SDK starter like me) but I always get the following exception:
{System.NullReferenceException: Invalid pointer at Nokia.Graphics.Imaging.BitmapRenderer.RenderAsync()
This is the code (I've reduced the part where the filters are passed so just an empty FilterEffect is passed on for simplicity):
PhotoChooserTask task = new PhotoChooserTask();
task.Completed += async (result,choosen) =>
{
Stream stream = choosen.ChosenPhoto;
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(stream);
WriteableBitmap bitmap = new WriteableBitmap(bitmapImage);
WriteableBitmapRenderer renderer = new WriteableBitmapRenderer(new FilterEffect(), bitmap, OutputOption.PreserveAspectRatio);
await renderer.RenderAsync();
};
task.ShowCamera = true;
task.Show();
So if I understood everything well, the app is crashing because some kind of invalid pointer is passed on, but the bitmap it valid - or at least the size of it is correct, so I guess, the data has been passed on, as well.
Anyway, here is the stacktrace
at Nokia.Graphics.Imaging.BitmapRenderer.RenderAsync()
at Nokia.Graphics.Imaging.WriteableBitmapRenderer.<<RenderAsync>b__0>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at RealtimeFilterDemo.MainPage.<<ShutterButton_Tap>b__1a>d__1c.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__0(Object state)
You're not setting a source image for the FilterEffect, and instead passing the source stream directly into the target WriteableBitmap for some reason.
When you kick off the RenderAsync operation, the FilterEffect Source property is null, and this is what causes the exception. You should pass an image source into either the FilterEffect constructor, or set its Source property.
I recommend a StreamImageSource since you've got a System.IO.Stream with the image data.
Conceptually, this is how to think of it:
chosen photo stream -> StreamImageSource -> FilterEffect -> WriteableBitmapRenderer -> the writeable bitmap
And more concretely:
using(var streamSource = new StreamImageSource(stream))
using(var filterEffect = new FilterEffect(streamSource, filters))
using(var writeableBitmapRenderer = new WriteableBitmapRenderer(filterEffect, writeableBitmap))
{
await writeableBitmapRenderer.RenderAsync();
....
}