Search code examples
c#asp.netimagebitmapsystem.drawing

How to create Bitmap from file on server - parameter is not valid


HttpRequest req = new HttpRequest(imageName, "http://panonest.com", "");
var imgSrc=req.MapPath("~/view/vacantapredeal/vacantapredeal.jpg");
Bitmap img = new Bitmap(imgSrc);

How should I do this? I get a parameter is not valid exception, which is thrown by the Bitmap constructor.


Solution

  • here is another way to do it:

      WebClient MyWebClient = new WebClient();
        byte[] BytesImage = MyWebClient.DownloadData("http://www.google.com/intl/en_com/images/srpr/logo3w.png");
        System.IO.MemoryStream iStream= new System.IO.MemoryStream(BytesImage);
        System.Drawing.Bitmap b = new System.Drawing.Bitmap(iStream);
    

    Good luck!