2

I'm developing a WP8 app using Nokia Imaging SDK. I'm trying to add filter effect to an image and render it into a WriteableBitmap.

Here is my code:

private async void PhotoChosen(object sender, PhotoResult photoResult)
    {
        if (photoResult != null)
        {
            BitmapImage bitmap = new BitmapImage();
            bitmap.SetSource(photoResult.ChosenPhoto);

            WriteableBitmap wb = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);

            StreamImageSource source = new StreamImageSource(photoResult.ChosenPhoto);

            var effects = new FilterEffect(source);
            effects.Filters = new IFilter[] { new SketchFilter() };
            var renderer = new WriteableBitmapRenderer(effects, wb);

            await renderer.RenderAsync();
        }
    }

All is going fine, but when this line is processing:

await renderer.RenderAsync();

This ArgumentException is thrown:

Value does not fall within the expected range

I think I've made a mistake creating the IImageProvider effects or the WriteableBitmap wb

Does anyone got this problem and found an issue ? Thanks :)

1 Answer 1

4

You need to set the stream position before setting it as source for StreamImageSource.

BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(photoResult.ChosenPhoto);

WriteableBitmap wb = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);

photoResult.ChosenPhoto.Position = 0;

StreamImageSource source = new StreamImageSource(photoResult.ChosenPhoto);

You need to do this because you have called bitmap.SetSource(photoResult.ChosenPhoto). That means that the stream has already been read once, therefore it's position is at the very end of the stream. When StreamImageSource tries to read it, it is already at the end, thus "Value does not fall within the expected range."

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.