如何从 Windows 应用商店应用程序中的图像控件将图像存储到 StorageFile 中?
我正在使用以下链接,但这对我来说没有用
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 http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefile.createstreamedfileasync.aspx
我的问题需要明确的解决方案。我怎样才能做到这一点?
您可以使用以下方法将 url 中的图像保存到以下文件中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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)