c# - 将远程图像保存到独立存储

标签 c# silverlight windows-phone-7

我尝试使用此代码下载图片:

void downloadImage(){
 WebClient client = new WebClient();
 client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
                client.DownloadStringAsync(new Uri("http://mysite/image.png"));

        }

void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
           //how get stream of image?? 
           PicToIsoStore(stream)
        }

        private void PicToIsoStore(Stream pic)
        {
            using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                var bi = new BitmapImage();
                bi.SetSource(pic);
                var wb = new WriteableBitmap(bi);
                using (var isoFileStream = isoStore.CreateFile("somepic.jpg"))
                {
                    var width = wb.PixelWidth;
                    var height = wb.PixelHeight;
                    Extensions.SaveJpeg(wb, isoFileStream, width, height, 0, 100);
                }
            }
        }

问题是:如何获取图片流?

谢谢!

最佳答案

在独立存储中获取文件流很容易。 IsolatedStorageFile 有一个 OpenFile获取一个的方法。

using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (IsolatedStorageFileStream stream = store.OpenFile("somepic.jpg", FileMode.Open))
    {
        // do something with the stream
    }
}

关于c# - 将远程图像保存到独立存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5870282/

相关文章:

c# - 具有外部源的 Entity Framework 6 同步表

windows - 枢轴控件中的 WP7 切换开关?

c# - 在 C# 中进行 Windows Phone 开发的 Intent

c# - 如何组织自定义 SQl 查询集合

c# - 如何在 Visual Studio 2013 中启用 C# 6.0 功能?

c# - 无需使用转义序列。在 C# 中为 '?

c# - 阻止并发调用者并从异步方法返回单个结果

excel - HTML5 + JS 替代品作为 Silverlight 应用程序的替代品

c# - 是否可以在 Windows Phone 中加密数据 AES ECB 模式?

c# - C#中的序列化