Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>public class CropImageManipulator { public CropImageManipulator() { } private string _fileNameWithoutExtension; private string _fileExtension; private string _fileDirectory; public void Cropping(string inputImgPath, int cropWidth, int cropHeight) { this._fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(inputImgPath); this._fileExtension = System.IO.Path.GetExtension(inputImgPath); this._fileDirectory = System.IO.Path.GetDirectoryName(inputImgPath); //Load the image divided Image inputImg = Image.FromFile(inputImgPath); int imgWidth = inputImg.Width; int imgHeight = inputImg.Height; //Divide how many small blocks int widthCount = (int)Math.Ceiling((imgWidth * 1.00) / (cropWidth * 1.00)); int heightCount = (int)Math.Ceiling((imgHeight * 1.00) / (cropHeight * 1.00)); ArrayList areaList = new ArrayList(); int i = 0; for (int iHeight = 0; iHeight &lt; heightCount ; iHeight ++) { for (int iWidth = 0; iWidth &lt; widthCount ; iWidth ++) { int pointX = iWidth * cropWidth; int pointY = iHeight * cropHeight; int areaWidth = ((pointX + cropWidth) &gt; imgWidth) ? (imgWidth - pointX) : cropWidth; int areaHeight = ((pointY + cropHeight) &gt; imgHeight) ? (imgHeight - pointY) : cropHeight; string s = string.Format("{0};{1};{2};{3}",pointX,pointY,areaWidth,areaHeight); Rectangle rect = new Rectangle(pointX,pointY,areaWidth,areaHeight); areaList.Add(rect); i ++; } } for (int iLoop = 0 ; iLoop &lt; areaList.Count ; iLoop ++) { Rectangle rect = (Rectangle)areaList[iLoop]; string fileName = this._fileDirectory + "\\" + this._fileNameWithoutExtension + "_" + iLoop.ToString() + this._fileExtension; Bitmap newBmp = new Bitmap(rect.Width,rect.Height,PixelFormat.Format24bppRgb); Graphics newBmpGraphics = Graphics.FromImage(newBmp); newBmpGraphics.DrawImage(inputImg,new Rectangle(0,0,rect.Width,rect.Height),rect,GraphicsUnit.Pixel); newBmpGraphics.Save(); switch (this._fileExtension.ToLower()) { case ".jpg": case ".jpeg": newBmp.Save(fileName,ImageFormat.Jpeg); break; case "gif": newBmp.Save(fileName,ImageFormat.Gif); break; } } inputImg.Dispose(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload