将远程图像保存到独立存储 [英] 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?
谢谢!
推荐答案
在你的 client_DownloadStringCompleted 中调用
方法PicToIsoStore
时,你需要把 e.Result
作为参数
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 的类型已经是 Stream
所以它已经准备好传递给你的方法 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屋!
查看全文