2

The constructor of WriteableBitmap class with Windows 8 only takes two arguments: the height and the width of this object. Meanwhile with Silverlight it accepts a BitmapImage object as argument. (Verified on MSDN : WriteableBitmap.WriteableBitmap constructor)

I would like to load this BitmapImage because I'm trying to blur an image which already exists on my Assets folder.

DIF
  • 2,470
  • 6
  • 35
  • 49
StevenTB
  • 405
  • 5
  • 19

2 Answers2

2

Thanks for your help, I succeed to blur my image. Here is the sample in order to link the BitmapImage into the WriteableBitmap object :

BitmapImage bi = new BitmapImage(new Uri(filename, UriKind.RelativeOrAbsolute));
WriteableBitmap wb = new WriteableBitmap(bi.PixelWidth, bi.PixelHeight);

var streamFile = await GetFileStream(myFile);
await wb.SetSourceAsync(streamFile);
wb = wb.Convolute(WriteableBitmapExtensions.KernelGaussianBlur5x5);

Then just write the WriteableBitmap into the LocalStorage !

StevenTB
  • 405
  • 5
  • 19
0

You should be able to load a BitmapImage into WritableBitmap like this:

WriteableBitmap writableBitmap = new WriteableBitmap(bitmapImage);

See here WriteableBitmap Constructor (BitmapSource)

DIF
  • 2,470
  • 6
  • 35
  • 49
  • 1
    I saw everywhere this but I don't have access to System.Windows.Media.Imaging but to Windows.UI.Xaml.Media.Imaging (I'm on Windows 8 RT, no Windows Phone 8.1) ... – StevenTB Apr 25 '14 at 08:24
  • This page indicates you'll have to use the `SetSource` or `SetSourceAsync` method for that: http://msdn.microsoft.com/de-de/library/windows/apps/dn263229.aspx – DIF Apr 25 '14 at 08:34
  • If you have access to the file itself, you could load it directly like this: `using (var stream = await file.OpenReadAsync()) { WriteableBitmap bitmap = new WriteableBitmap(width, height); await bitmap.SetSourceAsync(stream); }` – DIF Apr 25 '14 at 08:57