我尝试使用此代码下载图片:
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/