I'm doing this way:
using Windows.Storage;
using Windows.UI.Xaml.Media.Imaging;
...
private async void LoadFiles()
{
StorageFolder folder = KnownFolders.SavedPictures;
IReadOnlyList<StorageFile> list = await folder.GetFilesAsync();
var images = new List<BitmapImage>();
if (list != null)
{
foreach (StorageFile file in list)
{
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
BitmapImage bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(stream);
images.Add(bitmapImage);
}
}
flipView.ItemsSource = images;
}
xaml
<FlipView x:Name="flipView"
SelectionChanged="flipView_SelectionChanged">
<FlipView.ItemTemplate>
<DataTemplate>
<Image Stretch="UniformToFill" Source="{Binding}" />
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
I get this exception
A first chance exception of type 'System.Exception' occurred in mscorlib.ni.dll
Additional information: The component cannot be found. (Exception from HRESULT: 0x88982F50)
at this line
await bitmapImage.SetSourceAsync(stream);
Please, what is the problem?
The program works but the problem was corrupted jpg files.
They had a 0 bytes size so the stream
could not be created.
Check if this variable has been created or if it's full of data.
User contributions licensed under CC BY-SA 3.0