6 System.SysUtils, System.Types, System.UITypes, System.Classes,
8 FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Ani, FMX.Layouts,
10 FMX.StdCtrls, FMX.TreeView, FMX.ListBox, FMX.Controls.Presentation, FMX.Edit,
11 FMX.EditBox, FMX.SpinBox, FMX.Graphics, System.Math, FMX.Effects,
16 ToolbarHolder: TLayout;
18 ToolbarPopupAnimation: TFloatAnimation;
20 ToolbarApplyButton: TButton;
21 ToolbarCloseButton: TButton;
22 ToolbarAddButton: TButton;
28 RadioButton1: TRadioButton;
29 RadioButton2: TRadioButton;
30 OpenDialog1: TOpenDialog;
44 ImageControl1: TImageControl;
45 PathLabel1: TPathLabel;
48 procedure ToolbarCloseButtonClick(Sender: TObject);
49 procedure FormGesture(Sender: TObject; const EventInfo: TGestureEventInfo;
50 var Handled: Boolean);
51 procedure FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char;
53 procedure Button3Click(Sender: TObject);
54 procedure Button11Click(Sender: TObject);
55 procedure Button9Click(Sender: TObject);
56 procedure Button1Click(Sender: TObject);
57 procedure ListBox1Change(Sender: TObject);
58 procedure FormPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
59 procedure Button4Click(Sender: TObject);
60 procedure Button7Click(Sender: TObject);
61 procedure Button8Click(Sender: TObject);
62 procedure SpinBox3Change(Sender: TObject);
63 procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
64 Shift: TShiftState; X, Y: Single);
65 procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
66 Shift: TShiftState; X, Y: Single);
67 procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
68 procedure Button12Click(Sender: TObject);
70 FGestureOrigin: TPointF;
71 FGestureInProgress: Boolean;
78 function CalMyRect(Size: Extended): TRectF;
80 procedure ShowToolbar(AShow: Boolean);
92 procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char;
95 if Key = vkEscape then
96 ShowToolbar(not ToolbarPopup.IsOpen);
99 procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
100 Shift: TShiftState; X, Y: Single);
102 if RadioButton2.IsChecked = true then
109 procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState;
112 if (RadioButton2.IsChecked = true) and (Downed = true) then
119 procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
120 Shift: TShiftState; X, Y: Single);
124 if RadioButton2.IsChecked = true then
130 i := -GradToDeg(50 * (Y - St.Y) / (X - St.X))
132 i := -GradToDeg(50 * (St.Y - Y) / (St.X - X));
133 ImageControl1.Bitmap.Rotate(i);
140 procedure TForm1.FormPaint(Sender: TObject; Canvas: TCanvas;
141 const ARect: TRectF);
146 if ImageControl1.Bitmap.IsEmpty = true then
148 if MyRect.Width > 500 then
150 if MyRect.Width > ImageControl1.Bitmap.Width + 200 then
152 i := Floor(ImageControl1.Bitmap.Width / 127);
154 MyRect := CalMyRect(i);
156 if (MyRect.Width + 500 > ImageControl1.Bitmap.Width) or
157 (MyRect.Height + 500 > ImageControl1.Bitmap.Height) then
158 Canvas.FillRect(RectF(0, 0, 2 * 350, 2 * 350), 0, 0, [], 1);
161 s := RectF(0, 0, 350, 350);
162 t := RectF(i - 250, j - 250, i + 100, j + 100);
163 Canvas.DrawBitmap(ImageControl1.Bitmap, t, s, 1, true);
165 s := RectF(350, 0, 350 * 2, 350);
166 t := RectF(i - 100, j - 250, i + 250, j + 100);
167 Canvas.DrawBitmap(ImageControl1.Bitmap, t, s, 1, true);
170 s := RectF(0, 350, 350, 350 * 2);
171 t := RectF(i - 250, j - 100, i + 100, j + 250);
172 Canvas.DrawBitmap(ImageControl1.Bitmap, t, s, 1, true);
174 s := RectF(350, 350, 350 * 2, 350 * 2);
175 t := RectF(i - 100, j - 100, i + 250, j + 250);
176 Canvas.DrawBitmap(ImageControl1.Bitmap, t, s, 1, true);
177 Canvas.DrawDashRect(RectF(250, 250, 450, 450), 0, 0, [], 1,
182 i := (ImageControl1.Bitmap.Width - 2 * 350) / 2;
183 j := (ImageControl1.Bitmap.Height - 2 * 350) / 2;
184 s := RectF(i, j, i + 2 * 350, j + 2 * 350);
185 Canvas.DrawBitmap(ImageControl1.Bitmap, s,
186 RectF(0, 0, 2 * 350, 2 * 350), 1, true);
187 i := (2 * 350 - MyRect.Width) / 2;
188 j := (2 * 350 - MyRect.Height) / 2;
189 Canvas.DrawDashRect(RectF(i, j, 2 * 350 - i, 2 * 350 - j), 0, 0, [], 1,
192 if (RadioButton2.IsChecked = true) and (Downed = true) then
193 Canvas.DrawLine(St, Gt, 0.5);
196 procedure TForm1.ListBox1Change(Sender: TObject);
200 s := ListBox1.Items[ListBox1.ItemIndex];
201 Button12Click(Sender);
202 ImageControl1.Bitmap.LoadFromFile(s);
204 MyRect := CalMyRect(SpinBox3.Value);
208 procedure TForm1.ToolbarCloseButtonClick(Sender: TObject);
210 Application.Terminate;
213 procedure TForm1.TrimImage;
218 t.Left:=Floor(MyRect.Left);
219 t.Right:=Floor(MyRect.Right);
220 t.Top:=Floor(MyRect.Top);
221 t.Bottom:=Floor(MyRect.Bottom);
226 s.CopyFromBitmap(ImageControl1.Bitmap,t,0,0);
227 s.SaveToFile(Label3.Text + '\' + ExtractFileName(ListBox1.Items[ListBox1.ItemIndex]));
233 procedure TForm1.Button11Click(Sender: TObject);
238 procedure TForm1.Button12Click(Sender: TObject);
240 ImageControl1.Bitmap.Rotate(-Angle);
242 if Sender = Button12 then
246 procedure TForm1.Button1Click(Sender: TObject);
248 if ListBox1.ItemIndex > -1 then
250 if (Sender = Button1) and (DirectoryExists(Label3.Text) = false) then
252 Button9Click(Sender);
253 if DirectoryExists(Label3.Text) = false then
256 if Sender = Button1 then
257 if (CheckBox1.IsChecked = false) or
258 (FileExists(Label3.Text + '\' + ExtractFileName(ListBox1.Items
259 [ListBox1.ItemIndex])) = false) then
261 else if MessageDlg('Assign File ?', TMsgDlgType.mtConfirmation,
262 mbOKCancel, 0) = mrOK then
264 if ListBox1.ItemIndex < ListBox1.Items.Count - 1 then
265 ListBox1.ItemIndex := ListBox1.ItemIndex + 1;
269 procedure TForm1.Button3Click(Sender: TObject);
271 if OpenDialog1.Execute = true then
273 ListBox1.Items.Assign(OpenDialog1.Files);
274 if ListBox1.Items.Count > 0 then
275 ListBox1.ItemIndex := 0;
279 procedure TForm1.Button4Click(Sender: TObject);
283 if Sender = Button4 then
286 i := -SpinBox1.Value;
287 MyRect.Top := MyRect.Top - i;
288 MyRect.Bottom := MyRect.Bottom - i;
292 procedure TForm1.Button7Click(Sender: TObject);
296 if Sender = Button7 then
299 i := -SpinBox1.Value;
300 MyRect.Left := MyRect.Left - i;
301 MyRect.Right := MyRect.Right - i;
305 procedure TForm1.Button8Click(Sender: TObject);
309 if ImageControl1.Bitmap.IsEmpty = true then
311 MyRect := CalMyRect(20);
312 if MyRect.Width > ImageControl1.Bitmap.Width + 200 then
314 i := ImageControl1.Bitmap.Width / 127;
319 SpinBox3.Value := MySize;
320 MyRect := CalMyRect(MySize);
325 SpinBox3.Value := 20;
330 procedure TForm1.Button9Click(Sender: TObject);
335 if SelectDirectory('Save Directory', t, s) = true then
339 if DirectoryExists(s) = false then
340 Showmessage('
\8aJ
\82¯
\82È
\82¢
\83f
\83B
\83\8c\83N
\83g
\83\8a\82ð
\8eg
\97p
\82µ
\82Ä
\82¢
\82Ü
\82·');
343 function TForm1.CalMyRect(Size: Extended): TRectF;
345 i, j, m, n: Extended;
352 m := (ImageControl1.Bitmap.Width - i) / 2;
353 n := (ImageControl1.Bitmap.Height - j) / 2;
354 result := RectF(m, n, m + i, n + j);
357 procedure TForm1.FormGesture(Sender: TObject;
358 const EventInfo: TGestureEventInfo; var Handled: Boolean);
362 if EventInfo.GestureID = igiPan then
364 if (TInteractiveGestureFlag.gfBegin in EventInfo.Flags) and
365 ((Sender = ToolbarPopup) or (EventInfo.Location.Y > (ClientHeight - 70)))
368 FGestureOrigin := EventInfo.Location;
369 FGestureInProgress := true;
372 if FGestureInProgress and (TInteractiveGestureFlag.gfEnd in EventInfo.Flags)
375 FGestureInProgress := false;
376 DX := EventInfo.Location.X - FGestureOrigin.X;
377 DY := EventInfo.Location.Y - FGestureOrigin.Y;
378 if (Abs(DY) > Abs(DX)) then
384 procedure TForm1.ShowToolbar(AShow: Boolean);
386 ToolbarPopup.Width := ClientWidth;
387 ToolbarPopup.PlacementRectangle.Rect :=
388 TRectF.Create(0, ClientHeight - ToolbarPopup.Height, ClientWidth - 1,
390 ToolbarPopupAnimation.StartValue := ToolbarPopup.Height;
391 ToolbarPopupAnimation.StopValue := 0;
393 ToolbarPopup.IsOpen := AShow;
396 procedure TForm1.SpinBox3Change(Sender: TObject);
398 if ((SpinBox3.Value > MySize) and (ImageControl1.Width > MyRect.Width)) or
399 (SpinBox3.Value < MySize) then
401 MySize := SpinBox3.Value;
402 MyRect := CalMyRect(SpinBox3.Value);
406 MySize := SpinBox3.Value;
407 MyRect := CalMyRect(MySize);