User1289595697 posted
Hi,
In my application, a user can upload an image. If its too large, it will automatically be scaled.
But when trying to save the new, scaled image, i get an exception saying 'file not found', and then the location of the image I have selected to upload.
this is the code:
private
void ScaleAndSaveImage(HttpPostedFile file,
string path, string name)
{
System.Drawing.Image original = System.Drawing.Image.FromFile(file.FileName);
int width = original.Width, height = original.Height;
float scale = 1;
// This will calculate how much the image will have to be scaled
if (width > height)
scale = (float) width / MAXWIDTH;
else
scale = (float) height / MAXHEIGHT;
// New width and height, scaled
width = (int)(width / scale);
height = (int)(height / scale);
// Creating and saving the image
System.Drawing.Image newImage =
new Bitmap(original,
new Size(width, height));
newImage.Save(path + name, System.Drawing.Imaging.ImageFormat.Jpeg);
}
The last line is when the error is thrown. The image, however, WILL be uploaded. But in its original size, not scaled. This is what's confusing me the most.
If anyone can give me any clues, it would be great ;)