Matt126
Matt126

Reputation: 997

How to convert a IStorageItem item to a BitmapImage

Does anyone know how to convert a IStorageItem item from CameraRoll into a BitmapImage?

Here is my Code:

        private async void Button_Click(object sender, RoutedEventArgs e)
        {

            StorageFolder picturesFolder = KnownFolders.CameraRoll;

            IReadOnlyList<IStorageItem> itemsList =
                await picturesFolder.GetItemsAsync();

            BitmapImage[] Images = new BitmapImage[itemsList.Count];
            int i = 0;

            foreach (var item in itemsList)
            {
                if (item is StorageFolder)
                {
                }
                else
                {
                    i++;

                    //Images[i].SetSource(item);

                }
            }
        }

Upvotes: 0

Views: 754

Answers (1)

ua741
ua741

Reputation: 1466

In your else block

else {
    using (var stream = await item.OpenReadAsync())
    {
        await Images[i].SetSourceAsync(stream);
    }
}

Upvotes: 2

Related Questions