在Windows 8 Metro C#中显示StorageFile
我想在资产管理系统的UI上显示一个图像文件。 我设法将该项目存储为StorageFile
。 我该如何显示它? 我试图在XAML 标签的Source中显示它。 是否有可能将
StorageFile
为Image
?
string path = @"Assets\mypicture.png"; StorageFile file = await InstallationFolder.GetFileAsync(path);
试试这个function
public async Task GetImageAsync(StorageFile storageFile) { BitmapImage bitmapImage = new BitmapImage(); FileRandomAccessStream stream = (FileRandomAccessStream)await storageFile.OpenAsync(FileAccessMode.Read); bitmapImage.SetSource(stream); Image image = new Image(); image.Source = bitmapImage; return image; }
请尝试以下方法:
public async Task GetBitmapAsync(StorageFile storageFile) { BitmapImage bitmap = new BitmapImage(); IAsyncOperation read = storageFile.OpenReadAsync(); IRandomAccessStream stream = await read; bitmap.SetSource(stream); return bitmap; }
以这种方式调用函数:
Image image = new Image(); image.Source = await GetBitmapAsync (file);
image.Source = new BitmapImage(new Uri(“file://”+ storageFile.Path))