I've been trying to apply a filter from Nokias Imaging SDK to a WriteableBitmap. So far, I didn't have any success. The "best" I got is the following, which crashes on renderer.RenderAsync()

MemoryStream stream = new MemoryStream(App.MainViewModel.Current.Album.Cover.ToByteArray());
StreamImageSource streamImage = new StreamImageSource(stream);
FilterEffect filters = new FilterEffect(streamImage);
WriteableBitmapRenderer renderer = new WriteableBitmapRenderer(filters);

BlurFilter blurFilter = new BlurFilter();
filters.Filters = new[] { blurFilter };
var result = await renderer.RenderAsync();

The ToByteArray() extension method on Cover (which is a WriteableBitmap), is provided by the WriteableBitmapEx library.

Has anyone had the same problem?

有帮助吗?

解决方案

You are getting an exception in renderer.RenderAsync() because you aren't setting a WriteableBitmap property of WriteableBitmapRenderer.

The WriteableBitmapRenderer can not create a WriteableBitmap for you, as it needs to be created on the UI thread. So you must create it yourself and pass it into the renderer object (either in a constructor or by setting the property).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top