如何使用WriteableBitmap扩展库来模糊图像?

时间:2013-09-23 09:46:10

标签: image windows-8 windows-runtime microsoft-metro winrt-xaml

这没有给我任何结果。代码有什么问题? BTW, the below code blurs the image.

var ImgFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/search.png"));
var wb = new WriteableBitmap(1, 1);
using (var strm = await ImgFile.OpenReadAsync())
{
    wb.SetSource(strm);
}
var wb2 = new WriteableBitmap(wb.PixelWidth,wb.PixelHeight);
var wb3 = WriteableBitmapExtensions.Convolute(wb2, WriteableBitmapExtensions.KernelGaussianBlur5x5);
PageBackground.Source = wb3;

1 个答案:

答案 0 :(得分:1)

您正在将图像加载到wb图像中,但您没有使用它来模糊(相反,您只是模糊wb2,它是空的)。 这应该有效:

var ImgFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/search.png"));
var wb = new WriteableBitmap(1, 1);
using (var strm = await ImgFile.OpenReadAsync())
{
     wb=await wb.FromStream(strm);
}
var wb3 = WriteableBitmapExtensions.Convolute(wb, WriteableBitmapExtensions.KernelGaussianBlur5x5);
PageBackground.Source = wb3;