public static List <Rectangle> FindRectangles(this Bitmap source, BooleanStructure invert) { try { var blobCounter = new BlobCounter(); if (invert.Value) { new Invert().ApplyInPlace(source); } blobCounter.ProcessImage(source); return(blobCounter.GetObjectsRectangles().ToList()); } catch (Exception ex) { throw new Exception($"Could not find the rectangle. Message: {ex.Message}", ex); } }
public static Bitmap GetScreenshot(this RectangleStructure screenArea, BooleanStructure relative) { if (screenArea.Value.Width < 1 || screenArea.Value.Height < 1) { throw new ArgumentException("ScreenSearchArea argument's parts can't be negative. Both width and height must be bigger than zero."); } try { var screenSearchArea = screenArea.Value; if (relative.Value) { screenSearchArea = screenArea.Value.GetRelativeArea(); } return(RobotWin32.GetPartOfScreen(screenSearchArea, PixelFormat.Format24bppRgb)); } catch (Exception ex) { throw new Exception($"Could not get the screenshot image. Message: {ex.Message}", ex); } }