Il codice, che seguirà,fa il resize di una immagine e ne
crea pure il thumbnail tutto ed esclusivamente mantenendone
le proporzioni (aspect ratio)...
credo che se lo studi un pò riuscirai a ricavarne ciò che
ti serve 
codice:
<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="System"%>
<%@ import Namespace="System.IO"%>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Drawing.Imaging" %>
<%@ import Namespace="System.Text.RegularExpressions" %>
<script Language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
int ThumbnailWidth = 800; // Larghezza massima dopo il quale l'immagine viene ridimensionata
int ThumbnailHeight = 600; // Altezza massima dopo il quale l'immagine viene ridimensionata
string strFileName = "";
string destinazione = "./";
double orgImgWidth = 0.0;
double orgImgHeight = 0.0;
double rThumbnailWidth = 0.0;
double rThumbnailHeight = 0.0;
System.Drawing.Image orgImage;
if (Request.QueryString["FileName"] != "")
{
strFileName = Convert.ToString(Request.QueryString["FileName"]);
if (Request.QueryString["percorso"] != "") destinazione = Convert.ToString(Server.MapPath(Request.QueryString["percorso"]));
else
destinazione = Convert.ToString(Server.MapPath(destinazione));
if (strFileName != "")
{
try
{
if (!File.Exists(destinazione + "/thumbs/" + strFileName))
{
orgImage = System.Drawing.Image.FromFile(Server.MapPath(strFileName));
using(Bitmap tmpImage = new Bitmap(orgImage))
{
rThumbnailWidth = ThumbnailWidth;
rThumbnailHeight = ThumbnailHeight;
orgImgWidth = tmpImage.Width;
orgImgHeight = tmpImage.Height;
if ((tmpImage.Width > ThumbnailWidth) || (tmpImage.Height > ThumbnailHeight))
{
if (tmpImage.Width != tmpImage.Height)
{
if (tmpImage.Width > tmpImage.Height)
{
// L > H => tH = (H * tL)/ L
rThumbnailWidth = ThumbnailWidth;
rThumbnailHeight = (double)((tmpImage.Height * ThumbnailWidth) / tmpImage.Width);
} // if (tmpImage.Width > tmpImage.Height)
else
{
if (tmpImage.Width < tmpImage.Height)
{
// L < H => tL = (L * tH)/ H
rThumbnailHeight = ThumbnailWidth;
rThumbnailWidth = (double)((tmpImage.Width * ThumbnailHeight) / tmpImage.Height);
} // if (tmpImage.Width < tmpImage.Height)
} // else
} // if (tmpImage.Width != tmpImage.Height)
} // if ((tmpImage.Width > ThumbnailWidth) || (tmpImage.Height > ThumbnailHeight))
else
{
rThumbnailHeight = tmpImage.Height;
rThumbnailWidth = tmpImage.Width;
} // else
} // using(Bitmap tmpImage = new Bitmap(orgImage))
using(Bitmap bitmap = new Bitmap(orgImage, (int)(rThumbnailWidth), (int)(rThumbnailHeight)))
{
if ((orgImage.Width > ThumbnailWidth) || (orgImage.Height > ThumbnailHeight)) // In questo caso viene creata e salvato il Thumbnail dell'immagine in thumbs.
{
Response.ContentType = orgImage.RawFormat.ToString();
bitmap.Save(Response.OutputStream, orgImage.RawFormat);
bitmap.Save(destinazione + "/thumbs/" + strFileName, orgImage.RawFormat);
} // if ((orgImage.Width > ThumbnailWidth) || (orgImage.Height > ThumbnailHeight))
else // L'immagine rientra già nella dimensione da noi decisa quindi non serve creargli il Thumbnail.
{
Response.ContentType = orgImage.RawFormat.ToString();
bitmap.Save(Response.OutputStream, orgImage.RawFormat);
} // else
} // using(Bitmap bitmap = new Bitmap(orgImage, (int)(rThumbnailWidth), (int)(rThumbnailHeight)))
} // if (!File.Exists(destinazione + "/thumbs/" + strFileName)
else // L'immagine viene Semplicemente letta dalla thumbs.
{
orgImage = System.Drawing.Image.FromFile(destinazione + "/thumbs/" + strFileName);
Response.ContentType = orgImage.RawFormat.ToString();
orgImage.Save(Response.OutputStream, orgImage.RawFormat);
} // else // L'immagine viene Semplicemente letta dalla thumbs.
} // try
catch (Exception ex)
{
Response.Write(ex.Message);
} // catch (Exception ex)
finally
{
Response.Write("\nRe-Coded by R.B. Riddick");
}
} // if (strFileName != "")
} // if (Request.QueryString["FileName"] != "")
}
</script>