简体   繁体   English

如何将IStorageItem项转换为BitmapImage

[英]How to convert a IStorageItem item to a BitmapImage

Does anyone know how to convert a IStorageItem item from CameraRoll into a BitmapImage? 有谁知道如何将一个IStorageItem项目从CameraRoll转换为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);

                }
            }
        }

In your else block 在你的else块中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM