Ciao a tutti
devo ridimensionare un file presente sul server:
FileStream file = new FileStream(Server.MapPath(foto), FileMode.Open, FileAccess.Read);
ResizeAndSave(file, cs.WidthFotoBig, cs.HeightFotoBig, Server.MapPath(FileNameBig));
ResizeAndSave(file, cs.WidthFotoSmall, cs.HeightFotoSmall, Server.MapPath(FileNameSmall));
file.Close();
public void ResizeAndSave(Stream imgStr,int Width, int Height,string FileName)
{
int imgHeight;
int imgWidth;
//creo il bitmap dallo stream
System.Drawing.Image bmpStream=System.Drawing.Image.FromStream(imgStr);
//scelta delle dimensioni delle immagini
if (bmpStream.Width>bmpStream.Height)
{
imgHeight=(Width*bmpStream.Height)/bmpStream.Width;
imgWidth=Width;
}
else
{
imgWidth=(Height*bmpStream.Width)/bmpStream.Height;
imgHeight=Height;
}
//creo un nuovo bitmap ridimensionandolo
Bitmap img=new Bitmap(bmpStream,new Size(imgWidth,imgHeight));
//salvo l'immagine ridimensionata
img.Save(FileName,System.Drawing.Imaging.ImageFormat.Jpeg);
}
Sull'ultima riga di codice ricevo questo messaggio di errore:
Se richiamo la stessa procedura passando un file che carico da un controllo input, non ho nessun problema.
Come risolvo il problema?
Grazie mille