Home/ASP.NET Forums/Advanced ASP.NET/System.Drawing/GDI+/How to convert System.Web.UI.WebControls.Image to System.Drawing.Imag...

How to convert System.Web.UI.WebControls.Image to System.Drawing.Image [Answered]RSS

3 replies

Last post Mar 09, 2011 01:11 AM by GauravSingla

  • Grace Chan

    Grace Chan

    Member

    5 Points

    34 Posts

    Re: How to convert System.Web.UI.WebControls.Image to System.Drawing.Image

    Mar 08, 2011 10:04 PM|Grace Chan|LINK

    I see. By the way, how can I load the image from this path :

    "~/HelperPages/GetImage.aspx?employeeID=123"

    to

    System.Drawing.Image image?

  • GauravSingla

    GauravSingla

    Member

    614 Points

    191 Posts

    Re: How to convert System.Web.UI.WebControls.Image to System.Drawing.Image

    Mar 09, 2011 01:11 AM|GauravSingla|LINK

    Hi,

     Use WebClient.DownloadData method to download binary data of your image. then load the binary data into System.Drawing.Image using its FromStream method.

     

    string url =Request.Url.Scheme+"://"+Request.Url.Authority+ HttpRuntime.AppDomainAppVirtualPath + "/HelperPages/GetImage.aspx?employeeID=123";
            System.Net.WebClient client = new System.Net.WebClient();
            byte []imageData= client.DownloadData(url);
            System.IO.MemoryStream stream = new System.IO.MemoryStream(imageData);
            System.Drawing.Image img = System.Drawing.Image.FromStream(stream);

     

    I hope it will help.

    Gaurav
    http://www.go4coding.com
  • ‹ Previous Thread|Next Thread ›