BlogEngine.Core.FileSystem.Image.CropImage C# (CSharp) Method

CropImage() public method

Crops an image by giving the crop start x & y co-ordinates and then the height & width to crop to. Making a perfect rectangle of the crop area.
public CropImage ( int x, int y, int width, int height ) : Image
x int the x co-ordinate
y int the y co-ordinate
width int the width to crop
height int the height to crop
return Image
        public Image CropImage(int x, int y, int width, int height)
        {
            try
            {
                Rectangle cropArea = new Rectangle(x, y, width, height);
                Bitmap target = new Bitmap(cropArea.Width, cropArea.Height);

                using (Graphics g = Graphics.FromImage(target))
                {
                    g.DrawImage(this.bitMap, new Rectangle(0, 0, width, height),
                                     new Rectangle(x, y, target.Width, target.Height),
                                     GraphicsUnit.Pixel);

                }
                //Bitmap bmpCrop = this.bitMap.Clone(cropArea, PixelFormat.DontCare);
                //this.bitMap = bmpCrop;
                //var nfile = BlogService.UploadFile(BmpToArray(this.bitMap), this.Name, this.ParentDirectory, true);
                //this.FileContents = nfile.FileContents;
                //nfile.Dispose();

                var nfile = BlogService.UploadFile(BmpToArray(target), this.Name, this.ParentDirectory, true);
                this.FileContents = nfile.FileContents;
                this.bitMap.Dispose();
                this.bitMap = null;
                return this;
            }
            catch
            {
                return this;
            }
        }