using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; namespace OCR_tester { public class Zone { protected Bitmap FullImage; protected List Zones; protected List Windows; protected Rectangle _bounds; public Rectangle Bounds { get => _bounds; private set => _bounds = value; } public Bitmap ZoneImage { get { Bitmap sample = new Bitmap(Bounds.Width, Bounds.Height); Graphics g = Graphics.FromImage(sample); g.DrawImage(FullImage, new Rectangle(0, 0, sample.Width, sample.Height), Bounds, GraphicsUnit.Pixel); return sample; } } public Zone(Image fullImage, Rectangle bounds) { FullImage = (Bitmap)fullImage; Init(bounds); } public Zone(Bitmap fullImage, Rectangle bounds) { FullImage = fullImage; Init(bounds); } private void Init(Rectangle bounds) { Bounds = bounds; Zones = new List(); Windows = new List(); } private void AddZone(Rectangle bounds) { if(Fits(bounds)) Zones.Add(new Zone(ZoneImage,bounds)); } private void AddWindow(Rectangle bounds) { if (Fits(bounds)) Windows.Add(new Window(ZoneImage,bounds)); } /// /// Checks if the given Rectangle fits in the current zone /// /// The Rectangle you want to check the fittment /// protected bool Fits(Rectangle inputRectangle) { if (inputRectangle.X + inputRectangle.Width > Bounds.Width || inputRectangle.Y + inputRectangle.Height > Bounds.Height || inputRectangle.X < 0 || inputRectangle.Y < 0) { return false; } else { return true; } } } }