locked
How to use writableBitmap.SetSource(IRandomAccessStream) method. RRS feed

  • Question

  • I have a image uri path(say "/Assets/Logo.png").

    How can i move it to WritableBitmap?

    something like: writableBitmap.SetSource(new Uri( "/Assets/Logo.png")); //which is not there

    I mean

    How can I get IRandomAccessStream? to set as source.

    Thanks in advance.


    Saturday, March 31, 2012 9:38 AM

Answers

  • var writeableBitmap = await LoadBitmap("Assets/Logo.png");
    
    public static async Task<WriteableBitmap> LoadBitmap(string relativePath)
    {
        var storageFile = await Package.Current.InstalledLocation.GetFileAsync(relativePath.Replace('/', '\\'));
        var stream = await storageFile.OpenReadAsync();
        var wb = new WriteableBitmap(1, 1);
        wb.SetSource(stream);
        return wb;
    }


    Filip Skakun

    Saturday, March 31, 2012 9:02 PM

All replies

  • var writeableBitmap = await LoadBitmap("Assets/Logo.png");
    
    public static async Task<WriteableBitmap> LoadBitmap(string relativePath)
    {
        var storageFile = await Package.Current.InstalledLocation.GetFileAsync(relativePath.Replace('/', '\\'));
        var stream = await storageFile.OpenReadAsync();
        var wb = new WriteableBitmap(1, 1);
        wb.SetSource(stream);
        return wb;
    }


    Filip Skakun

    Saturday, March 31, 2012 9:02 PM
  • thanks ITs working
    Tuesday, October 23, 2012 7:01 AM