【问题标题】:WriteableBitmapRenderer.RenderAsync() ArgumentException "Value does not fall within the expected range"WriteableBitmapRenderer.RenderAsync() ArgumentException“值不在预期范围内”
【发布时间】:2014-01-16 20:06:30
【问题描述】:

我正在使用 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 effectsWriteableBitmap wb 时犯了一个错误

有没有人遇到这个问题并发现了问题? 谢谢:)

【问题讨论】:

    标签: windows-phone-8 writeablebitmap argumentexception nokia-imaging-sdk lumia-imaging-sdk


    【解决方案1】:

    您需要先设置流位置,然后再将其设置为 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 试图读取它时,它已经在末尾,因此“值不在预期范围内。”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-12
      • 1970-01-01
      • 1970-01-01
      • 2011-08-09
      • 1970-01-01
      相关资源
      最近更新 更多