StevenTB
StevenTB

Reputation: 410

Load BitmapImage into WriteableBitmap but no method existing

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.

Upvotes: 2

Views: 8479

Answers (2)

StevenTB
StevenTB

Reputation: 410

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 !

Upvotes: 2

dif
dif

Reputation: 2493

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

WriteableBitmap writableBitmap = new WriteableBitmap(bitmapImage);

See here WriteableBitmap Constructor (BitmapSource)

Upvotes: 0

Related Questions