Picture path
String OldPath = Server.MapPath ("/111.jpg");
New picture Path
String NewPath = System.IO.Path.GetExtension (OldPath);
Set the Intercept's coordinates and size
int x = $, y = 0, Width = $, height = 500;
Calculates a new file name and adds _new after the old file name
NewPath = oldpath.substring (0, Oldpath.length-newpath.length) + "_new" + NewPath;
Response.Write (OldPath);
Response.Write ("<br>");
Response.Write (NewPath);
Response.Write ("<br>");
Defining an intercept Rectangle
System.Drawing.Rectangle Croparea = new System.Drawing.Rectangle (x, y,width, height); The size of the area to intercept
Loading pictures
System.Drawing.Image img = System.Drawing.Image.FromStream (New System.IO.MemoryStream (System.IO.File.ReadAllBytes ( (OldPath)));
Determine the position of the excess no
If (img. Width < x + width) | | Img. Height < y + height)
{
Response.Write ("The captured area exceeds the height and width of the image itself.");
Img. Dispose ();
Return
}
Defining Bitmap objects
System.Drawing.Bitmap bmpimage = new System.Drawing.Bitmap (IMG);
to crop
System.Drawing.Bitmap Bmpcrop = Bmpimage.clone (Croparea, Bmpimage.pixelformat);
Save As new file
Bmpcrop.save (NewPath);
Releasing objects
Img. Dispose ();
Bmpcrop.dispose ();
Response.Write ("cutting success");
ASP. NET Picture Trimming