uwp Images Load Image from StorageFile

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

public static async Task<ImageSource> FromStorageFile(StorageFile sf)
{
    using (var randomAccessStream = await sf.OpenAsync(FileAccessMode.Read))
    {
        var result = new BitmapImage();
        await result.SetSourceAsync(randomAccessStream);
        return result;
    }
}

Use result to set the Source property of an Image control either though a Binding or code-behind

Useful when you need to open images that are stored on the user's disk and not shipped with your application



Got any uwp Question?