将映像从映像控件存储到StorageFile



如何从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

我的问题需要明确的解决方案。我该怎么做?

您可以使用以下方法将图像从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;
}

最新更新