Load image from a URL(Web) and draw it

image_pdfimage_print
   
  
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://international.us.server12.fileserver.kutayzorlu.com/files/download/2017/01/1_uuid-04f7b0dd-dbeb-4b4c-b943-2f5f92486379_crc-2185242360.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);
     }
}

   
     


This entry was posted in 2D Graphics. Bookmark the permalink.