Store image in to StorageFile from image control

后端 未结 1 715
独厮守ぢ
独厮守ぢ 2021-01-07 13:28

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 =          


        
相关标签:
1条回答
  • 2021-01-07 14:04

    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;
    }
    
    0 讨论(0)
提交回复
热议问题