我想在资产的 UI 上显示一个图像文件。我设法将项目存储为StorageFile
. 我怎样才能显示它?我试图在 XAML<Image>
标记的源中显示它。可以隐瞒StorageFile
吗Image
?
string path = @"Assets\mypicture.png";
StorageFile file = await InstallationFolder.GetFileAsync(path);
我想在资产的 UI 上显示一个图像文件。我设法将项目存储为StorageFile
. 我怎样才能显示它?我试图在 XAML<Image>
标记的源中显示它。可以隐瞒StorageFile
吗Image
?
string path = @"Assets\mypicture.png";
StorageFile file = await InstallationFolder.GetFileAsync(path);
试试这个功能
public async Task<Image> 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<BitmapImage> GetBitmapAsync(StorageFile storageFile)
{
BitmapImage bitmap = new BitmapImage();
IAsyncOperation<IRandomAccessStream> 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))