0

我试图从 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))

我不知道是什么问题,尽管我认为图像可能没有正确插入到隔离存储中。

4

1 回答 1

1

我不认为你需要"~/SherutApp1;component/"那里的部分。如果你整个路径是"test.jpg"或者"folderThatExists\\test.jpg"它应该工作。

于 2012-06-20T14:04:11.027 回答