Files
OCR_TEST/OCR_tester/Zone.cs
T

74 lines
2.2 KiB
C#

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<Zone> Zones;
protected List<Window> 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<Zone>();
Windows = new List<Window>();
}
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));
}
/// <summary>
/// Checks if the given Rectangle fits in the current zone
/// </summary>
/// <param name="InputRectangle">The Rectangle you want to check the fittment</param>
/// <returns></returns>
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;
}
}
}
}