Store image in to StorageFile from image control

微笑、不失礼 提交于 2019-11-30 20:56:42

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/14786460/store-image-in-to-storagefile-from-image-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!