Hi,
我写了一份程序,能够从图片文件夹中读取一张图片,并把缩略图放入BitmapImage类中可以用于显示:
private async void getContent()
{
StorageFolder folder = KnownFolders.PicturesLibrary;
StorageFile file = await folder.GetFileAsync("test1.jpg");
IRandomAccessStream thumbnail = await file.GetThumbnailAsync(ThumbnailMode.PicturesView);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(thumbnail);
}
这里面有一些需要注意的地方:
第一,Win8 Style App有严格的文件访问限制,具体可以参考这篇文章:
http://msdn.microsoft.com/en-us/library/windows/apps/Hh967755.aspx
第二,官方也提供了一个提取缩略图的程序,不过缩略图存储在用于存放缩略图的结构StorageItemThumbnail中,你可以看看这个example:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.fileproperties.storageitemthumbnail.aspx
因为StorageItemThumbnail实现了IRandomAccessStream所以我直接用这个接口取出后放入了BitmapImage中,其实两个基本一样。
Hope this helps
Aaron Xue [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
