Search code examples
c#asp.netsystem.drawing

Saving an image with SaveJpeg fires an error related to Image


I'm using the following code to resize and save an uploaded image to the srever with SaveJpeg. When I run my code I get an error: Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawin...

 ....
HttpPostedFile imageFile = uploadedFile;
                            string newname = System.DateTime.Now.ToString("yyMMdd-hhmmss-") + uploadedFile.FileName;

                            System.Drawing.Image bm = System.Drawing.Image.FromStream(imageFile.InputStream);
                            bm = ResizeBitmap((Bitmap)bm, 200); /// new width, height                                                                          

                            // Save the image with a quality of 50%
                            SaveJpeg(System.IO.Path.Combine(Server.MapPath("/Members/images/BG/"), newname), bm, 50); 
 .....


public static void SaveJpeg(string path, Image bm, int quality)
   {
code stuff

}

Solution

  • try this change this line

    public static void SaveJpeg(string path, System.Drawing.Image bm, int quality)
    {
       code stuff
    
    }
    

    you are using System.Web.UI.WebControls image and System.Drawing Image without giving prper identification. this is the reason compiler got confused between these two differant type of images.