OcrLibrary.Helpers.Screenshot.Crop C# (CSharp) Method

Crop() public method

Crops the image (removes some toolbars)
public Crop ( ) : void
return void
        public void Crop()
        {
            if (Image == null) return;
            const int margin = 20;
            var cropArea = new Rectangle(
                0, //x
                5 * margin, //y
                Image.Width, //width
                Image.Height - 7 * margin); // height

            var bmpImage = new Bitmap(Image);

            // TODO: memory exception because of image is not within boundaries sometimes
            var bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);

            Image = bmpCrop;
            Save("cropping");

            // free up memory
            bmpCrop.Dispose();
            bmpCrop = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }