I have such method for saving image from url:
public Image DownloadImage(string _URL)
{
Image _tmpImage = null;
try
{
// Open a connection
System.Net.HttpWebRequest _HttpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(_URL);
_HttpWebRequest.AllowWriteStreamBuffering = true;
// You can also specify additional header values like the user agent or the referer: (Optional)
_HttpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0";
_HttpWebRequest.Referer = url;
// set timeout for 20 seconds (Optional)
_HttpWebRequest.Timeout = timeout;
// Request response:
System.Net.WebResponse _WebResponse = _HttpWebRequest.GetResponse();
// Open data stream:
System.IO.Stream _WebStream = _WebResponse.GetResponseStream();
// convert webstream to image
_tmpImage = Image.FromStream(_WebStream);
// Cleanup
_WebResponse.Close();
}
catch (Exception e)
{
// Error
new Log(id++, DateTime.Now, e.ToString() + e.Message);
return null;
}
return _tmpImage;
}
and call this method:
Image _Image = null;
_Image = DownloadImage("https://***" + img_url);
System.Runtime.InteropServices.ExternalException (0x80004005): В GDI+ error occured
in System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
in System.Drawing.Image.Save(String filename, ImageFormat format)
in System.Drawing.Image.Save(String filename)
in konslat.TermSh.getAndSaveImage() в
what i do wrong, and how to solve this?