I'm using WriteableBitmapEX library trying to blur a Bitmap image at windows phone 8 I tried this code
Uri uri = new Uri(AnyUri, UriKind.RelativeOrAbsolute);
BitmapImage img1 = new BitmapImage();
img1.UriSource = uri;
img1.CreateOptions = BitmapCreateOptions.None;
WriteableBitmap wbm = new WriteableBitmap(img1);
var wbm2 = WriteableBitmapExtensions.Convolute(wbm, WriteableBitmapExtensions.KernelGaussianBlur5x5);
PanoramaBackground.ImageSource = wbm2;
But there is an exception "Object reference not set to an instance of an object"
at the line WriteableBitmap wbm = new WriteableBitmap(img1);
Why this doesn't work ??
This should work:
WriteableBitmap bitmap = BitmapFactory.New(0, 0).FromContent("RelativePathHere.png");
var blurredBitmap = WriteableBitmapExtensions.Convolute(bitmap, WriteableBitmapExtensions.KernelGaussianBlur5x5);
ImageControl.Source = blurredBitmap;
EDIT
OK so it looks like you are getting the image from the web and you are having an exception because the image is not loaded yet. You need to subscribe to the ImageOpened event handler. Here is the code:
Uri uri = new Uri("AbsoluteUriPath.png", UriKind.Absolute);
BitmapImage img1 = new BitmapImage(uri);
img1.CreateOptions = BitmapCreateOptions.None;
img1.ImageOpened += (s, e) =>
{
WriteableBitmap bitmap = new WriteableBitmap(img1);
var blurredBitmap = WriteableBitmapExtensions.Convolute(bitmap,
WriteableBitmapExtensions.KernelGaussianBlur5x5);
ImageControl.Source = blurredBitmap;
};