Convert StorageFile to a BitmapImage in Universal Windows Apps

We have already seen how to convert a WritableBitmap to a StorageFile in Universal Windows apps.

A StorageFile can be converted to a BitmapImage using the following function.

public class ImageUtils
    public static async Task<BitmapImage> StorageFileToBitmapImage(StorageFile savedStorageFile)
        using (IRandomAccessStream fileStream = await savedStorageFile.OpenAsync(Windows.Storage.FileAccessMode.Read))
            BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.DecodePixelHeight = 100;
            bitmapImage.DecodePixelWidth = 100;
            await bitmapImage.SetSourceAsync(fileStream);
            return bitmapImage;

To use the function call it as follows.

BitmapImage imageSource= await ImageUtils.StorageFileToBitmapImage(savedStorageFile);

convert a WritableBitmap to a StorageFile in Universal Windows apps

Vivek Maskara

I am pursuing BTech in Software Engineering from Delhi Technological University. I develop apps, create websites and blog about my app experiences.

  • Arun Prasad

    i want to convert the bitmapimage to storage file

Read more:
How to create your first Windows Phone app
How to change the App name and Tile name of your Windows phone app
Data binding in Windows Phone app – One way binding