在独立存储保存远程图片 [英] Save a remote image in to Isolated Storage
本文介绍了在独立存储保存远程图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用下载的图片的代码:
I tried using this code for download image:
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);
}
}
}
现在的问题是:怎么弄图像的流?
The problem is: how get the stream of image?
感谢!
推荐答案
您需要打电话时,把 e.Result
作为参数 PicToIsoStore
您在 client_DownloadStringCompleted
法
You need to put e.Result
as a parameter when calling PicToIsoStore
inside your client_DownloadStringCompleted
method
void client_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e)
{
PicToIsoStore(e.Result);
}
WebClient类得到的响应,并将其存储在 e.Result
变量。如果你仔细看,e.Result的类型已经是流
,使其准备好要传递给你的方法 PicToIsoStore
The WebClient class gets response and stores it in the e.Result
variable. If you look carefully, the type of e.Result is already Stream
so it is ready to be passed to your method PicToIsoStore
这篇关于在独立存储保存远程图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文