WP 8.1 - 如果知道图像 URL 如何将图像保存到独立存储

WP 8.1 - How to save an image to Isolated Storage if know it's URL

我有图像URL

如何在 WP 8.1 中保存它到隔离存储

我可以同时触发保存然后分享 一键上传到 Facebook?

这是我的代码 - 遵循 Burak Kaan Köse 的代码运行良好:

public async void GetImage()
    {
        StorageFolder folder = ApplicationData.Current.LocalFolder;
            if (folder != null)
            {
                StorageFile file = await folder.CreateFileAsync("imagefile", CreationCollisionOption.ReplaceExisting);

                string url = imgUri[fLFl.SelectedIndex].ToString();
                HttpClient client = new HttpClient();
                byte[] fileContent = await client.GetByteArrayAsync(url); ; // This is where you set your content as byteArray

                Stream fileStream = await file.OpenStreamForWriteAsync();
                fileStream.Write(fileContent, 0, fileContent.Length);
                fileStream.Flush();
                fileStream.Dispose();
            }
    }

不要忘记更改 'imagefile' 路径和 fileContent 变量。

private async void SaveFile()
{
    try
    {
        StorageFolder folder = ApplicationData.Current.LocalFolder;
        if(folder != null)
        {
            StorageFile file = await folder.CreateFileAsync("imagefile", CreationCollisionOption.ReplaceExisting);
            byte[] fileContnet = null; // This is where you set your content as byteArray
            Stream fileStream = await file.OpenStreamForWriteAsync();
            fileStream.Write(fileContent, 0, fileContent.Length);
            fileStream.Flush();
            fileStream.Close();
        }
    }
    catch (Exception ex)
    {
        // Some Exception handling code
    }
}