从图像控制中StorageFile店面形象 [英] Store image in to StorageFile from image control

查看:110
本文介绍了从图像控制中StorageFile店面形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在存储图像StorageFile从Windows Store应用程序图像控制?我使用下面的链接,但不适合我。

how can i store image in to StorageFile from image control in windows store apps? I'm using following link but that is not useful for me

StorageFile file = await StorageFile.CreateStreamedFileFromUriAsync(" ", new Uri(user.ProfilePicUrl), new RandomAccessStream());

http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefile.createstreamedfileasync.aspx

我需要为我的问题明确的解决方案。我怎样才能做到这一点?

I need clear solution for my problem. How can I do this?

推荐答案

您可以用下面的方法来从URL保存图像文件的 LocalFolder

You can use the following method to save an image from an url to a file in LocalFolder:

public async Task<string> DownloadFileAsync(Uri uri, string filename)
{
    using (var fileStream = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(filename, CreationCollisionOption.ReplaceExisting))
    {
        var webStream = await new HttpClient().GetStreamAsync(uri);
        await webStream.CopyToAsync(fileStream);
        webStream.Dispose();
    }
    return (await ApplicationData.Current.LocalFolder.GetFileAsync(filename)).Path;
}

这篇关于从图像控制中StorageFile店面形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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