Logo UGIdotNET

Discussione 'Convert to JPG'

# Pubblicato il 23 ott 2003 12.16 - Rispondi
christoph p
Convert to JPG
ciao ragazzi
allor i ho un problema con il resize delle imagine
io sto faccendo un upload di imagine in una pagina web .. ho trovato un belissimo pezzo di codice che lavora benissimo .. l'unico porblema le imagine sono un po grandi, i thumbnail hanno una grandezza di ca 20 kb e le imagine originale hanno una grandezza di 400 kb e piu. qualcuno sa come faccio a farel piu piccole in kb perche la grandezza width e height devono restare cosi

ecco il codice:
public static void SaveImage(HttpPostedFile file, string strFolderName, int intID)
{
Image imgFull = Image.FromStream(file.InputStream);
Image imgTumb = Image.FromStream(file.InputStream);
imgFull = ResizeImage(imgFull, 640, 480);
imgTumb = ResizeImage(imgTumb, 120, 90);
UploadFile(imgFull, strFolderName, false, intID);
UploadFile(imgTumb, strFolderName, true, intID);
}

private static Image ResizeImage(Image img, int width, int height)
{
Bitmap b;
Image i;
Graphics g ;

if(img.Width < img.Height)
b = new Bitmap(height, width);
else
b = new Bitmap(width, height);

i = Image.FromHbitmap(b.GetHbitmap(System.Drawing.Color.Transparent));
g = Graphics.FromImage(i);
if(img.Width < img.Height)
g.DrawImage(img,0f,0f,height, width);
else
g.DrawImage(img,0f,0f,width, height);
g.Dispose();
img.Dispose();
return i;
}

private static void UploadFile(Image image, string strFolderName, bool blnCreateThumbnail, int intID)
{
if(!blnCreateThumbnail)
image.Save(HttpContext.Current.Server.MapPath(String.Format(@"..\uploadImages\{0}\{1}.jpg", strFolderName, intID.ToString())) ,ImageFormat.Jpeg);
else
image.Save(HttpContext.Current.Server.MapPath(String.Format(@"..\uploadTumbs\{0}\{1}.jpg", strFolderName, intID.ToString())) ,ImageFormat.Jpeg);
}

qualcuno ha un idea??
grazie
slauti christoph
# Pubblicato il 23 ott 2003 16.43 - Rispondi
fratnik
Re: Convert to JPG


Bitmap b.SetResolution( x,y);


----------------------
Questo messaggio è stato postato da microsoft.public.it.dotnet.csharp.

© 2001 User Group Italiano UGIdotNET. Tutti i diritti riservati. Note legali. - Partita IVA 01927050185