First time I found helpfull to push this to git
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
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
|
||||
{
|
||||
private Bitmap FullImage;
|
||||
private List<Zone> Zones;
|
||||
private List<Window> Windows;
|
||||
|
||||
private 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>();
|
||||
}
|
||||
public void AddZone(Rectangle bounds)
|
||||
{
|
||||
if(Fits(bounds))
|
||||
Zones.Add(new Zone(ZoneImage,bounds));
|
||||
}
|
||||
public 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>
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user