SoFunction
Updated on 2025-03-08

C# to implement the method of cropping pictures on the server side

This article describes the method of C# to implement the cropping of pictures on the server side. Share it for your reference. The specific implementation method is as follows:

//Picture pathString oldPath = ("~/");
//New picture pathString newPath = (oldPath);
//Set the intercepted coordinates and sizeint x = 0, y = 20, width = 200, height = 2400;
// Calculate the new file name and add _new after the old file namenewPath = (0,  - ) + "_new" + newPath;
(oldPath);
("<br>");
(newPath);
//Define the cut-off rectangle cropArea = new (x, y, width, height); //The area size to be intercepted//Load the picture img = (new ((oldPath)));
//Judge whether the exceeded positionif (( < x + width) ||  < y + height)
{
 ("The intercepted area exceeds the height and width of the picture itself.");
 ();
 return;
}
//Define Bitmap object bmpImage = new (img);
//Cutting bmpCrop = (cropArea, );
//Save it as a new file(newPath);
//Release the object();
();

I hope this article will be helpful to everyone's C# programming.