2

Nokia Imaging SDK を使用して WP8 アプリを開発しています。画像にフィルター効果を追加して、WriteableBitmap.

これが私のコードです:

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();
        }
    }

すべてうまくいっていますが、この行が処理されているとき:

await renderer.RenderAsync();

これArgumentExceptionがスローされます:

Value does not fall within the expected range

IImageProvider effectsまたはの作成を間違えたと思いますWriteableBitmap wb

誰かがこの問題を抱えて問題を見つけましたか? ありがとう :)

4

1 に答える 1

4

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);

を呼び出したので、これを行う必要がありますbitmap.SetSource(photoResult.ChosenPhoto)。これは、ストリームが既に一度読み取られていることを意味するため、その位置はストリームの最後にあります。StreamImageSource が読み込もうとすると、すでに最後にあるため、「値が期待される範囲内にありません」。

于 2014-01-16T21:55:43.133 に答える