Can't use URI System.Drawing.Image.FromFile RRS feed

  • Question

  • User-860945821 posted

    Is it possible to somehow use the URI with this code?

     System.Drawing.Image uploadedImgPhoto = System.Drawing.Image.FromFile("http://www.example.com/ben.jpg");
     uploadedImgPhoto.Save(context.Response.OutputStream, ImageFormat.Jpeg);

    Currently it errors out on this line
     System.Drawing.Image uploadedImgPhoto = System.Drawing.Image.FromFile("http://www.example.com/ben.jpg");

    With the error
    System.ArgumentException: URI formats are not supported.


    Any suggestions or work arounds?



    Friday, October 13, 2006 7:05 PM

All replies

  • User-1395392389 posted

    Download the Image server-side using a function like this one (System.Net.WebClient is the key tool):

    Function GetFilePathFromUrl(ByVal url As String) As String
       Dim webC As New System.Net.WebClient
       Dim fileName As String = url.Split("/")(url.Split("/").Length - 1)
       fileName = Server.MapPath("../{DownloadFolder}/" & _
                  Guid.NewGuid().ToString & "_" & fileName)
       webC.DownloadFile(url, fileName)
       Return Server.MapPath(fileName)
    End Function

     then you can create the bitmap instance and do whatever you need.

    Hope it helps

    Saturday, October 14, 2006 3:31 AM