Crop Image

Crop Image

Description:
This code try to demonstrate how to return a crop image, from a original one, passed as parameter.
 
Code:

       using System.Drawing;

        public Image ManualCrop(Image image, int cropMargin)
        {
            Rectangle cropRect = new Rectangle(cropMargin, cropMargin, image.Width - cropMargin * 2, image.Height - cropMargin * 2);
                
            Bitmap bmpImage = new Bitmap(image);
                
            if (cropRect.Width < 0 ||
                cropRect.Height < 0 ||
                cropRect.X + cropRect.Width > image.Width ||
                cropRect.X + cropRect.Width > image.Width)
            {
                cropRect.Width = 0;
            }

            Bitmap bmpCrop = bmpImage.Clone(cropRect, bmpImage.PixelFormat);
            return (Image)(bmpCrop);            
        }
Leave a Comment
  • Please add 2 and 4 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
Page 1 of 1 (1 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
Page 1 of 1 (1 items)