我正在编写一个C#UWP应用程序,该应用程序显示用户照片库中的图像。我想看看如何获取所有照片并在GridViewItem和flipviewitem中显示每张照片。
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
var pictureQueryOptions = new QueryOptions();
//Read through all the subfolders.
pictureQueryOptions.FolderDepth = FolderDepth.Deep;
//Apply the query on the PicturesLibrary
var pictureQuery = KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(pictureQueryOptions);
//
var picturesInformation = new FileInformationFactory(pictureQuery, ThumbnailMode.PicturesView);
picturesSource.Source = picturesInformation.GetVirtualizedFilesVector();
}
和
public class ImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string culture)
{
if (value != null)
{
var img = (IRandomAccessStream)value;
var picture = new BitmapImage();
picture.SetSource(img);
return picture;
}
return DependencyProperty.UnsetValue;
}
public object ConvertBack(object value, Type targetType, object parameter, string culture)
{
throw new NotImplementedException();
}
}
使用此构造函数,最简单的代码修复方法是增加缩略图的大小(它们最多可以达到1024px,因此就足够了):
FileInformationFactory.FileInformationFactory(IStorageQueryResultBase, ThumbnailMode, UInt32, ThumbnailOptions)
除此之外,您可以像这样从StorageFile设置BitmapImage:https : //social.msdn.microsoft.com/Forums/en-US/bc9aa758-f211-468b-8168-a671b7a0c8b4/uwp-creating-bitmapimage-with-uri从相同的uri提供文件中获取异常?forum = wpdevelop
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句