我试图从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))
我不知道是什么问题,虽然我认为图像可能无法正确插入隔离存储。
答案 0 :(得分:1)
我认为你不需要"~/SherutApp1;component/"
部分。如果您的整个路径为"test.jpg"
或"folderThatExists\\test.jpg"
,则应该有效。