static System.Drawing.Image CropImage(string path, int Width, int Height, int Left, int Top)
{
String newPath = path;
if (newPath.Length > 2)
{
if (newPath.Substring(1, 1) != ":" && !newPath.StartsWith(@"\\"))
{
newPath = HttpContext.Current.Server.MapPath(newPath);
}
}
System.Drawing.Image imgPhoto = System.Drawing.Image.FromFile(newPath);
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
Bitmap bmPhoto = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
grPhoto.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
grPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
grPhoto.DrawImage(imgPhoto,
new Rectangle(0, 0, Width, Height),
new Rectangle(Left, Top, Width, Height),
GraphicsUnit.Pixel);
imgPhoto.Dispose();
grPhoto.Dispose();
return bmPhoto;
}