我试图从 URL 获取图像并将其存储在我的隔离存储中,然后从隔离存储中获取图像这里是我的相关代码:
public void GetImages()
{
string uri = "http://sherutnetphpapi.cloudapp.net/mini_logos/" + path;
WebClient m_webClient = new WebClient();
imageUri = new Uri(uri);
m_webClient.OpenReadAsync(imageUri);
m_webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_ImageOpenReadCompleted);
m_webClient.AllowReadStreamBuffering = true;
}
void webClient_ImageOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
string iso_path = "~/SherutApp1;component/" + path;
var isolatedfile = IsolatedStorageFile.GetUserStoreForApplication();
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(iso_path, FileMode.Create, isolatedfile))
{
byte[] buffer = new byte[e.Result.Length];
while (e.Result.Read(buffer, 0, buffer.Length) > 0)
{
stream.Write(buffer, 0, buffer.Length);
}
}
}
我在这一行的标题处得到了例外:
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(iso_path, FileMode.Create, isolatedfile))
我不知道是什么问题,尽管我认为图像可能没有正确插入到隔离存储中。