@@ -16,6 +16,8 @@ internal static class ImageCropping
16
16
{
17
17
internal static void StartCrop ( )
18
18
{
19
+ if ( mainWindow . img . Source == null ) { return ; }
20
+
19
21
if ( cropppingTool == null )
20
22
{
21
23
LoadControls . LoadCroppingTool ( ) ;
@@ -30,7 +32,7 @@ internal static void StartCrop()
30
32
) ) ) ;
31
33
}
32
34
33
- if ( mainWindow . img . Source == null ) { return ; }
35
+ mainWindow . Bar . Text = "Press Esc to close, Enter to save" ;
34
36
35
37
if ( ! mainWindow . bg . Children . Contains ( cropppingTool ) )
36
38
{
@@ -48,9 +50,19 @@ internal static void StartCrop()
48
50
1 ) ;
49
51
50
52
cropppingTool . CropTool . SetImage ( i ) ;
51
- cropppingTool . CropTool . SetSize ( mainWindow . img . Source . Width , mainWindow . img . Source . Height ) ;
52
- cropppingTool . CropTool . Width = xWidth ;
53
- cropppingTool . CropTool . Height = xHeight ;
53
+ if ( Rotateint == 0 || Rotateint == 180 )
54
+ {
55
+ cropppingTool . CropTool . SetSize ( mainWindow . img . Source . Width , mainWindow . img . Source . Height ) ;
56
+ cropppingTool . CropTool . Width = xWidth ;
57
+ cropppingTool . CropTool . Height = xHeight ;
58
+ }
59
+ else
60
+ {
61
+ cropppingTool . CropTool . SetSize ( mainWindow . img . Source . Height , mainWindow . img . Source . Width ) ;
62
+ cropppingTool . CropTool . Width = xHeight ;
63
+ cropppingTool . CropTool . Height = xWidth ;
64
+ }
65
+
54
66
}
55
67
56
68
internal static async void SaveCrop ( )
@@ -83,11 +95,43 @@ internal static Int32Rect GetCrop()
83
95
{
84
96
var cropArea = cropppingTool . CropTool . CropService . GetCroppedArea ( ) ;
85
97
86
- // Incorrect coordinates calculated if image resized to fit app, help!
87
- var x = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . X ) ;
88
- var y = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Y ) ;
89
- var width = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Width ) ;
90
- var height = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Height ) ;
98
+ int x , y , width , height ;
99
+
100
+ if ( AspectRatio != 0 )
101
+ {
102
+ if ( Rotateint == 0 || Rotateint == 180 )
103
+ {
104
+ x = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . X / AspectRatio ) ;
105
+ y = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Y / AspectRatio ) ;
106
+ width = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Width / AspectRatio ) ;
107
+ height = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Height / AspectRatio ) ;
108
+ }
109
+ else
110
+ {
111
+ x = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Y / AspectRatio ) ;
112
+ y = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . X / AspectRatio ) ;
113
+ width = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Height / AspectRatio ) ;
114
+ height = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Width / AspectRatio ) ;
115
+ }
116
+
117
+ }
118
+ else
119
+ {
120
+ if ( Rotateint == 0 || Rotateint == 180 )
121
+ {
122
+ x = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . X ) ;
123
+ y = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Y ) ;
124
+ width = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Width ) ;
125
+ height = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Height ) ;
126
+ }
127
+ else
128
+ {
129
+ x = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Y ) ;
130
+ y = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . X ) ;
131
+ width = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Height ) ;
132
+ height = Convert . ToInt32 ( cropArea . CroppedRectAbsolute . Width ) ;
133
+ }
134
+ }
91
135
92
136
return new Int32Rect ( x , y , width , height ) ;
93
137
}
0 commit comments