1
votes

Hi I'm having a problem with Windows Phone 8.1 Universal app. I have to create a WriteableBitmap from an image i have on the phone. I have my uri

Uri uri = new Uri("ms-appx;/Images/imageName.png");

but i honestly don't know how to use it to create a WriteableBitmap. I found a lot of solutions but they all use

WriteableBitmap wb = new WriteableBitmap(bitmapImageName);

This code is not working on Windows Phone 8.1, the only constructor avaiable is

WriteableBitmap wb = new WriteableBitmap(pixelHeight, pixelWidth);

bit i honestly don't know what to do.

Any help will be appreciated

Thanks all

1
You can try this. var uri = new Uri("ms-appx;/Images/imageName.png"); var storageFile = await StorageFile.GetFileFromApplicationUriAsync(uri); var wb = new WriteableBitmap(pixelHeight, pixelWidth); using (var stream = await storageFile.OpenReadAsync()) { await wb.SetSourceAsync(stream); } - RavingDev
@BlueRay i get Value does not fall within the expected range when using GetFileromApplicationUriAsync :( - Pier Giorgio Misley
Uri uri = new Uri("ms-appx:///Images/imageName.png"); - RavingDev
Worked! thanks a lot, if you add the reply i vote it :) - Pier Giorgio Misley

1 Answers

2
votes
var uri = new Uri("ms-appx:///Images/imageName.png");
var storageFile = await StorageFile.GetFileFromApplicationUriAsync(uri);
var writeableBitmap = new WriteableBitmap(pixelHeight, pixelWidth);
using (var stream = await storageFile.OpenReadAsync())
{
    await writeableBitmap.SetSourceAsync(stream);
}