如何从Web加载图像并将图像保存到隔离存储?

时间:2012-05-09 10:26:49

标签: windows-phone-7

String url1 =“http://localhost/Images/Map.png”;
我想从此链接加载图像“Map.png”,然后保存到隔离存储。

2 个答案:

答案 0 :(得分:0)

public void GetImages()

    {

            WebClient m_webClient = new WebClient();

            Uri m_uri = new Uri("http://localhost/Images/Map.png");

            m_webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);

            m_webClient.OpenReadAsync(m_uri);

        }             


   void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        int count;

        Stream stream = e.Result;

        byte[] buffer = new byte[1024];

使用(IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())

        {

            // isf.Remove();
            //if (!isf.FileExists("map"))
            //{


            using (System.IO.IsolatedStorage.IsolatedStorageFileStream isfs = new IsolatedStorageFileStream("map", FileMode.Create, isf))
            {
                count = 0;

                while (0 < (count = stream.Read(buffer, 0, buffer.Length)))
                {
                    isfs.Write(buffer, 0, count);
                }

                stream.Close();
                isfs.Close();
            }
        }

答案 1 :(得分:0)