Problema resize immagini lato server

78fede78

Nuovo Utente
17 Ago 2006
1
0
0
www.venditacase.org
Buongiorno ho scritto una funzione che fa il resize di immagini prima
di dalvarle sul server.
nel caso di png e jpg funziona perfettamente
le gif ridimensionate inve sono "sporche" la potete visualizzare ".


il codice è il seguente:


private bool salvaRidimensiona(Stream imgStr,string percorso,string
nome,string estensione)
{
const double MaxWidth=450.00;
const double MaxHeight=300.00;
bool stato= false;
double distorsione=1;
System.Drawing.Image
bmpStream=System.Drawing.Image.FromStream(imgStr);
if(bmpStream.Width>200 || bmpStream.Height>130)
{
stato=true;
//l'immagine necessita un ridimensionamento proporzionato
double rapLarg=bmpStream.Width/MaxWidth;
double rapAlt=bmpStream.Height/MaxHeight;
if(rapLarg>rapAlt)
{
distorsione=1/rapLarg;
}
else
{
distorsione=1/rapAlt;
}
int nuovaAltezza=(int)(Math.Round(bmpStream.Height*distorsione));
int nuovaLarghezza=(int)(Math.Round(bmpStream.Width*distorsione));
int altezzaRidotta = (int)(Math.Round(nuovaAltezza/2.0));
int larghezzaRidotta =(int)(Math.Round(nuovaLarghezza/2.0));


Bitmap img = new Bitmap(bmpStream,new
Size(nuovaLarghezza,nuovaAltezza));
Bitmap img2 = new Bitmap(bmpStream,new
Size(larghezzaRidotta,altezzaRidotta));


if(estensione==".jpg")
{
img.Save(percorso+nome+estensione,System.Drawing.Imaging.ImageFormat.Jpeg);
img2.Save(percorso+nome+"small"+estensione,System.Drawing.Imaging.ImageForm*at.Jpeg);
}
else if(estensione==".gif")
{
img.Save(percorso+nome+estensione,System.Drawing.Imaging.ImageFormat.Gif);
img2.Save(percorso+nome+"small"+estensione,System.Drawing.Imaging.ImageForm*at.Gif);
}
else if(estensione==".png")
{
img.Save(percorso+nome+estensione,System.Drawing.Imaging.ImageFormat.Png);
img2.Save(percorso+nome+"small"+estensione,System.Drawing.Imaging.ImageForm*at.Png);
}
}
return stato;
}






http://www.venditacase.org
 

Discussioni simili