将图像从图像控件存储到 StorageFile [英] Store image in to StorageFile from image control

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

问题描述

如何将图像从 Windows 商店应用程序中的图像控件存储到 StorageFile?我正在使用以下链接,但这对我没有用

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天全站免登陆