private void button1_Click(object sender, System.EventArgs e)
        {
            WebRequest request = WebRequest.Create("http://www.microsoft.com/library/toolbar/3.0/images/banners/ms_masthead_ltr.gif");
            request.Credentials = CredentialCache.DefaultCredentials;            StreamReader sr = new StreamReader( "c:\\ms_masthead_ltr.gif" ) ;
            MemoryStream ms = new MemoryStream();            byte[] data = new byte[256];
            int c = sr.Read(data, 0, data.Length);            while (c > 0) 
            {
                ms.Write(data, 0, c);
                c = source.Read(data, 0, data.Length);
            }            source.Close();
            ms.Position = 0;
            pictureBox1.Image = new Bitmap(ms);
        }

解决方案 »

  1.   

    string path ="../images/a.gif";
    Stream source = File.OpenRead(path); 
    byte[] data  = new byte[256];
    source.Read(data ,0,data .Length);
    MemoryStream ms = new MemoryStream();
    int c = source.Read(data, 0, data.Length);
    while (c > 0) 
    {
       ms.Write(data, 0, c);
       c = source.Read(data, 0, data.Length);
    }
    source.Close();
    ms.Position = 0;
    pictureBox1.Image = new Bitmap(ms);
      

  2.   

    本地的Path可以直接转换为Uri,构造一个Uri对象,仍然使用原来的读取网络图片的程序。