locked
Image.save(filename) Error RRS feed

  • Question

  • User856206699 posted

    Hi Friends,

    FtpWebResponse response;
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(path);
    request.KeepAlive = false;

    request.Method = WebRequestMethods.Ftp.DownloadFile;
    // This example assumes the FTP site uses anonymous logon.
    request.Credentials = new NetworkCredential(userId, password);
    response = (FtpWebResponse)request.GetResponse();

    Stream responseStream = response.GetResponseStream();
    var image = Image.FromStream(responseStream);
    image.Save(tempfileloc,);
    image.Dispose();
    responseStream.Close();
    responseStream.Dispose();
    response.Close();

    I am using the above code to download Images from remote server.

    I can getting above 30k images from remote server, i can download images but for some images when saving i am getting such error

    System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
    at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
    at System.Drawing.Image.Save(String filename, ImageFormat format)
    at System.Drawing.Image.Save(String filename)

    Please help me out 

    Thank you.

    Tuesday, April 9, 2013 4:09 PM

Answers

  • User856206699 posted

    Hi All, 

    Got answer, this is what i did so i am not getting that error 

    FtpWebResponse response;
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(path);
    request.KeepAlive = false;
    request.UseBinary=true;
    request.Method = WebRequestMethods.Ftp.DownloadFile;
    // This example assumes the FTP site uses anonymous logon.
    request.Credentials = new NetworkCredential(userId, password);
    response = (FtpWebResponse)request.GetResponse();

    Stream responseStream = response.GetResponseStream();

    var image = Image.FromStream(responseStream);

    int newWidth=image.Width;
    int newHeight = image.Height;

    Bitmap newImage = new Bitmap(newWidth, newHeight);
    using (Graphics gr = Graphics.FromImage(newImage))
    {
    gr.SmoothingMode = SmoothingMode.HighQuality;
    gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
    gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
    gr.DrawImage(image, new Rectangle(0, 0, newWidth, newHeight));
    newImage.Save(tempfileloc);
    }
    //image.Save(tempfileloc,ImageFormat.Jpeg);
    imageList.Add(uri);
    image.Dispose();
    responseStream.Close();
    responseStream.Dispose();
    response.Close();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 10, 2013 5:28 PM

All replies

  • User-1716253493 posted
    maybe wrong path, can you post the code?
    Tuesday, April 9, 2013 7:17 PM
  • User856206699 posted

    Hi, 

    Path is right. But i am getting that error due to security symantec end point protection while saving the image. 

    Is the image format is wrong or anything else ?

    I can get images except some images with this issue, is there any other way that i can get those images.

    Wednesday, April 10, 2013 12:02 PM
  • User856206699 posted

    Hi All, 

    Got answer, this is what i did so i am not getting that error 

    FtpWebResponse response;
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(path);
    request.KeepAlive = false;
    request.UseBinary=true;
    request.Method = WebRequestMethods.Ftp.DownloadFile;
    // This example assumes the FTP site uses anonymous logon.
    request.Credentials = new NetworkCredential(userId, password);
    response = (FtpWebResponse)request.GetResponse();

    Stream responseStream = response.GetResponseStream();

    var image = Image.FromStream(responseStream);

    int newWidth=image.Width;
    int newHeight = image.Height;

    Bitmap newImage = new Bitmap(newWidth, newHeight);
    using (Graphics gr = Graphics.FromImage(newImage))
    {
    gr.SmoothingMode = SmoothingMode.HighQuality;
    gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
    gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
    gr.DrawImage(image, new Rectangle(0, 0, newWidth, newHeight));
    newImage.Save(tempfileloc);
    }
    //image.Save(tempfileloc,ImageFormat.Jpeg);
    imageList.Add(uri);
    image.Dispose();
    responseStream.Close();
    responseStream.Dispose();
    response.Close();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 10, 2013 5:28 PM