1

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

Pier Giorgio Misley
  • 5,305
  • 4
  • 27
  • 66
  • 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 Sep 10 '15 at 10:57
  • @BlueRay i get Value does not fall within the expected range when using GetFileromApplicationUriAsync :( – Pier Giorgio Misley Sep 10 '15 at 11:01
  • Uri uri = new Uri("ms-appx:///Images/imageName.png"); – RavingDev Sep 10 '15 at 11:13
  • Worked! thanks a lot, if you add the reply i vote it :) – Pier Giorgio Misley Sep 10 '15 at 12:09

1 Answers1

2
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);
} 
RavingDev
  • 2,817
  • 1
  • 17
  • 19