Mapping StorageFile in Windows 8 Metro C #

I would like to display the image file in the user interface from Assets. I managed to save the item as StorageFile . How can I display it? I tried to display it in the source of the XAML <Image> . Can I hide a StorageFile before Image ?

 string path = @"Assets\mypicture.png"; StorageFile file = await InstallationFolder.GetFileAsync(path); 
+4
source share
3 answers

Try this feature

 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; } 
+9
source

Try the following:

 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; } 

Call the function as follows:

 Image image = new Image(); image.Source = await GetBitmapAsync (file); 
+2
source

image.Source = new BitmapImage (new Uri ("file: //" + storageFile.Path))

+1
source

Source: https://habr.com/ru/post/1437021/


All Articles