我正在尝试从 URL 获取图像并将其保存到隔离存储中,而不是从隔离存储中获取它并在我的 WP-7 应用程序中显示它。
这是相关的代码:
public void GetImages()
{
string uri = "http://sherutnetphpapi.cloudapp.net/mini_logos/" + path;
WebClient m_webClient = new WebClient();
imageUri = new Uri(uri);
m_webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_ImageOpenReadCompleted);
m_webClient.OpenReadAsync(imageUri);
}
void webClient_ImageOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
Stream stream = e.Result;
using (IsolatedStorageFile myIsf = IsolatedStorageFile.GetUserStoreForApplication())
{
IsolatedStorageFileStream fileStream = myIsf.CreateFile(path);
StreamResourceInfo sri = null;
sri = Application.GetResourceStream(imageUri);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(sri.Stream);
WriteableBitmap wb = new WriteableBitmap(bitmap);
// Encode WriteableBitmap object to a JPEG stream.
System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
fileStream.Close();
}
}
问题出在这一行:sri = Application.GetResourceStream(imageUri);
我在此方法上遇到异常GetResourceStream()
预期的相对 Uri,发现是绝对的。
我不明白用什么方法代替imageUri
.
提前致谢!!