WebRequest.GetResponse() : WebRequest « System.Net « C# / C Sharp by API






WebRequest.GetResponse()

 
using System;
using System.Drawing;
using System.IO;
using System.Net;
using System.Windows.Forms;
   
class ImageFromWeb: Form
{
     Image image;
   
     public static void Main()
     {
          Application.Run(new ImageFromWeb());
     }
     public ImageFromWeb()
     {
          ResizeRedraw = true;
          WebRequest   webreq = WebRequest.Create("http://www.yoursite.com/1.jpg");
          WebResponse  webres = webreq.GetResponse();
          Stream       stream = webres.GetResponseStream();
   
          image = Image.FromStream(stream);
          stream.Close();
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
     }     
     protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
     {
          grfx.DrawImage(image, 0, 0);
     }
}

   
  








Related examples in the same category

1.WebRequest.Create(Uri u)