显示在Windows 8地铁C#中的StorageFile [英] Display a StorageFile in Windows 8 Metro C#

查看:390
本文介绍了显示在Windows 8地铁C#中的StorageFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示从资产UI中的图像文件。我设法项存储为 StorageFile 。我该如何显示呢?我试图在XAML <来显示它;图像> 标签的来源。是否有可能隐蔽 StorageFile 图片



 路径字符串= @Assets\mypicture.png 
StorageFile文件=等待InstallationFolder.GetFileAsync(路径);


解决方案

试试这个功能。



 公共异步任务<图像> GetImageAsync(StorageFile storageFile)
{
的BitmapImage BitmapImage的=新的BitmapImage();
FileRandomAccessStream流=(FileRandomAccessStream)等待storageFile.OpenAsync(FileAccessMode.Read);
bitmapImage.SetSource(流);
图像形象=新的图像();
image.Source = BitmapImage的;
返回图像;
}


I would like to display an image file on the UI from the Assets. I managed to store the item as a StorageFile. How can I display it? I've tried to display it in a XAML <Image> tag's Source. Is it possible to covert StorageFile to Image?

string path = @"Assets\mypicture.png";
StorageFile file = await InstallationFolder.GetFileAsync(path);

解决方案

Try this function

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

这篇关于显示在Windows 8地铁C#中的StorageFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆