簡體   English   中英

在Windows 8 Metro C#中顯示StorageFile

[英]Display a StorageFile in Windows 8 Metro C#

我想在資產管理系統的UI上顯示一個圖像文件。 我設法將項目存儲為StorageFile 我該如何顯示它? 我試圖在XAML <Image>標簽的Source中顯示它。 是否有可能將StorageFileImage

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))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM