1

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)
David Božjak
  • 16,887
  • 18
  • 67
  • 98
jalgames
  • 781
  • 4
  • 23

1 Answers1

4

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();
    ....
}
CÅdahl
  • 442
  • 3
  • 13
  • Thanks a lot! Seems to work. I guess it happend because the Imaging SDK documentation is so poor:) – jalgames Mar 27 '14 at 20:30
  • Actually there should be many samples similar to the above. :) What would you like to see added to the documentation? – CÅdahl Mar 27 '14 at 22:01
  • I guess the problem is all the samples are sooo complicated. I mean, the code above is essentially all you need for a simple filter application, but all the samples contain dozens of files with helper classes containing hundreds of code lines. It just is too complicated to understand all that code for just a simple supper mechanism. – jalgames Mar 28 '14 at 05:53
  • 2
    @user2241553 have you looked at the QuickStart sample: http://developer.nokia.com/resources/library/Lumia/nokia-imaging-sdk/quick-start.html ? It should be exactly what you are looking for. – David Božjak Mar 28 '14 at 06:59
  • Oh, yes... Had seen that once but forgotten about it:) – jalgames Mar 29 '14 at 07:32