我正在使用诺基亚成像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
是否有人遇到此问题并发现问题? 谢谢:))
答案 0 :(得分: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尝试读取它时,它已经在最后,因此“值不在预期范围内。”