1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
using System;
using System.Drawing;
namespace UVtools.Core.Operations
{
public enum Anchor : byte
{
TopLeft, TopCenter, TopRight,
MiddleLeft, MiddleCenter, MiddleRight,
BottomLeft, BottomCenter, BottomRight,
None
}
public class OperationMove
{
public Rectangle SrcRoi { get; set; }
private Rectangle _dstRoi = Rectangle.Empty;
public Rectangle DstRoi
{
get
{
if(!_dstRoi.IsEmpty) return _dstRoi;
CalculateDstRoi();
return _dstRoi;
}
}
public void CalculateDstRoi()
{
_dstRoi.Size = SrcRoi.Size;
switch (Anchor)
{
case Anchor.TopLeft:
_dstRoi.Location = new Point(0, 0);
break;
case Anchor.TopCenter:
_dstRoi.Location = new Point((int)(ImageWidth / 2 - SrcRoi.Width / 2), 0);
break;
case Anchor.TopRight:
_dstRoi.Location = new Point((int)(ImageWidth - SrcRoi.Width), 0);
break;
case Anchor.MiddleLeft:
_dstRoi.Location = new Point(0, (int)(ImageHeight / 2 - SrcRoi.Height / 2));
break;
case Anchor.MiddleCenter:
_dstRoi.Location = new Point((int)(ImageWidth / 2 - SrcRoi.Width / 2), (int)(ImageHeight / 2 - SrcRoi.Height / 2));
break;
case Anchor.MiddleRight:
_dstRoi.Location = new Point((int)(ImageWidth - SrcRoi.Width), (int)(ImageHeight / 2 - SrcRoi.Height / 2));
break;
case Anchor.BottomLeft:
_dstRoi.Location = new Point(0, (int)(ImageHeight - SrcRoi.Height));
break;
case Anchor.BottomCenter:
_dstRoi.Location = new Point((int)(ImageWidth / 2 - SrcRoi.Width / 2), (int)(ImageHeight - SrcRoi.Height));
break;
case Anchor.BottomRight:
_dstRoi.Location = new Point((int)(ImageWidth - SrcRoi.Width), (int)(ImageHeight - SrcRoi.Height));
break;
default:
throw new ArgumentOutOfRangeException();
}
_dstRoi.X += MarginLeft;
_dstRoi.X -= MarginRight;
_dstRoi.Y += MarginTop;
_dstRoi.Y -= MarginBottom;
}
public uint ImageWidth { get; set; }
public uint ImageHeight { get; set; }
public Anchor Anchor { get; set; }
public int MarginLeft { get; set; } = 0;
public int MarginTop { get; set; } = 0;
public int MarginRight { get; set; } = 0;
public int MarginBottom { get; set; } = 0;
public OperationMove(Rectangle srcRoi, uint imageWidth = 0, uint imageHeight = 0, Anchor anchor = Anchor.MiddleCenter)
{
SrcRoi = srcRoi;
ImageWidth = imageWidth;
ImageHeight = imageHeight;
Anchor = anchor;
}
}
}
|