///
/// This function used for setting the size of image at run time
///
///
///
public void AutoImageSize(string orgpath, string modpath, int size)
{
//int maxDimension = 153;//this value can be any thing......
int maxDimension = size;
Bitmap bm = new Bitmap(orgpath);
double num = ((float)bm.Width) / ((float)bm.Height);
if (System.IO.File.Exists(modpath))
{
System.IO.File.Delete(modpath);
}
if ((num > 1.0) && (bm.Width > maxDimension))
{
System.Drawing.Image image = new Bitmap(maxDimension, (int)(((double)maxDimension) / num));
Graphics graphics = Graphics.FromImage(image);
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.DrawImage(bm, 0, 0, maxDimension, (int)(((double)maxDimension) / num));
image.Save(modpath);
image.Dispose();
}
else if (bm.Height > maxDimension)
{
System.Drawing.Image image = new Bitmap((int)(maxDimension * num), maxDimension);
Graphics graphics = Graphics.FromImage(image);
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.DrawImage(bm, 0, 0, (int)(maxDimension * num), maxDimension);
image.Save(modpath);
image.Dispose();
}
else
{
System.Drawing.Image image = new Bitmap(bm);
image.Save(modpath);
image.Dispose();
}
bm.Dispose();
}
//How to Call
//comobj.AutoImageSize(Request.PhysicalApplicationPath + "Admin/Places/Actual/" + //objImageName.ToString(), Request.PhysicalApplicationPath + "Admin/Places/Actual/" + //"_UploadPlaceImg" + imgcnt + objImageName.ToString(), 120);