| 1 |
unit Unit1; |
| 2 |
|
| 3 |
interface |
| 4 |
|
| 5 |
uses |
| 6 |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
| 7 |
Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls, FileCtrl, ExtDlgs, Jpeg, Math, |
| 8 |
System.Types, System.UITypes; |
| 9 |
|
| 10 |
type |
| 11 |
TRGB = record |
| 12 |
R: Byte; |
| 13 |
G: Byte; |
| 14 |
B: Byte; |
| 15 |
end; |
| 16 |
|
| 17 |
TRGBArray = array [Word] of TRGB; |
| 18 |
|
| 19 |
PRGBArray = ^TRGBArray; |
| 20 |
|
| 21 |
TForm1 = class(TForm) |
| 22 |
ListBox1: TListBox; |
| 23 |
Button1: TButton; |
| 24 |
Button2: TButton; |
| 25 |
Panel1: TPanel; |
| 26 |
SpeedButton4: TSpeedButton; |
| 27 |
SpeedButton5: TSpeedButton; |
| 28 |
SpeedButton6: TSpeedButton; |
| 29 |
SpeedButton7: TSpeedButton; |
| 30 |
SpeedButton8: TSpeedButton; |
| 31 |
SpeedButton9: TSpeedButton; |
| 32 |
Image1: TImage; |
| 33 |
Edit3: TEdit; |
| 34 |
UpDown1: TUpDown; |
| 35 |
DirectoryListBox1: TDirectoryListBox; |
| 36 |
Label1: TLabel; |
| 37 |
Button3: TButton; |
| 38 |
OpenPictureDialog1: TOpenPictureDialog; |
| 39 |
Label2: TLabel; |
| 40 |
CheckBox1: TCheckBox; |
| 41 |
Button4: TButton; |
| 42 |
Label3: TLabel; |
| 43 |
Button5: TButton; |
| 44 |
Bevel1: TBevel; |
| 45 |
Label4: TLabel; |
| 46 |
Edit1: TEdit; |
| 47 |
SpeedButton1: TSpeedButton; |
| 48 |
UpDown2: TUpDown; |
| 49 |
RadioButton1: TRadioButton; |
| 50 |
RadioButton2: TRadioButton; |
| 51 |
Label5: TLabel; |
| 52 |
procedure Button1Click(Sender: TObject); |
| 53 |
procedure ListBox1Click(Sender: TObject); |
| 54 |
procedure ListBox1KeyDown(Sender: TObject; var Key: Word; |
| 55 |
Shift: TShiftState); |
| 56 |
procedure FormPaint(Sender: TObject); |
| 57 |
procedure FormCreate(Sender: TObject); |
| 58 |
procedure SpeedButton9Click(Sender: TObject); |
| 59 |
procedure SpeedButton8Click(Sender: TObject); |
| 60 |
procedure SpeedButton5Click(Sender: TObject); |
| 61 |
procedure SpeedButton4Click(Sender: TObject); |
| 62 |
procedure Button3Click(Sender: TObject); |
| 63 |
procedure FormMouseDown(Sender: TObject; Button: TMouseButton; |
| 64 |
Shift: TShiftState; X, Y: Integer); |
| 65 |
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, |
| 66 |
Y: Integer); |
| 67 |
procedure FormMouseUp(Sender: TObject; Button: TMouseButton; |
| 68 |
Shift: TShiftState; X, Y: Integer); |
| 69 |
procedure Button4Click(Sender: TObject); |
| 70 |
procedure Button5Click(Sender: TObject); |
| 71 |
procedure RadioButton1Click(Sender: TObject); |
| 72 |
procedure SpeedButton1Click(Sender: TObject); |
| 73 |
procedure RadioButton2Click(Sender: TObject); |
| 74 |
private |
| 75 |
{ Private ���� } |
| 76 |
MyRect: TRect; |
| 77 |
MySize: integer; |
| 78 |
MouseDown: Boolean; |
| 79 |
DownedPos: TPoint; |
| 80 |
Gt: TPoint; |
| 81 |
function CalMyRect: TRect; |
| 82 |
procedure TrimImage; |
| 83 |
public |
| 84 |
{ Public ���� } |
| 85 |
end; |
| 86 |
|
| 87 |
var |
| 88 |
Form1: TForm1; |
| 89 |
|
| 90 |
implementation |
| 91 |
|
| 92 |
{$R *.dfm} |
| 93 |
|
| 94 |
procedure TForm1.Button1Click(Sender: TObject); |
| 95 |
begin |
| 96 |
if (Sender = Button1)and(ListBox1.ItemIndex > -1) then |
| 97 |
begin |
| 98 |
if (CheckBox1.Checked = true)and(FileExists(DirectoryListBox1.GetItemPath(DirectoryListBox1.ItemIndex) |
| 99 |
+'\_'+ExtractFileName(ListBox1.Items[ListBox1.ItemIndex])) = true) then |
| 100 |
begin |
| 101 |
if MessageDlg('Assign file ?',mtConfirmation,[mbYes,mbCancel],0) = mrOK then |
| 102 |
begin |
| 103 |
TrimImage; |
| 104 |
end; |
| 105 |
end else |
| 106 |
begin |
| 107 |
TrimImage; |
| 108 |
end; |
| 109 |
end; |
| 110 |
if ListBox1.ItemIndex < ListBox1.Count-1 then |
| 111 |
begin |
| 112 |
ListBox1.ItemIndex:=ListBox1.ItemIndex+1; |
| 113 |
end; |
| 114 |
ListBox1Click(Sender); |
| 115 |
end; |
| 116 |
|
| 117 |
procedure TForm1.ListBox1Click(Sender: TObject); |
| 118 |
var |
| 119 |
img: TPicture; |
| 120 |
begin |
| 121 |
if ListBox1.ItemIndex > -1 then |
| 122 |
begin |
| 123 |
img:=TPicture.Create; |
| 124 |
try |
| 125 |
Caption:=ListBox1.Items[ListBox1.ItemIndex]; |
| 126 |
img.LoadFromFile(Caption); |
| 127 |
Image1.Picture.Bitmap.Assign(img.Graphic); |
| 128 |
finally |
| 129 |
img.Free; |
| 130 |
end; |
| 131 |
FormPaint(Sender); |
| 132 |
end; |
| 133 |
end; |
| 134 |
|
| 135 |
procedure TForm1.ListBox1KeyDown(Sender: TObject; var Key: Word; |
| 136 |
Shift: TShiftState); |
| 137 |
begin |
| 138 |
ListBox1Click(Sender); |
| 139 |
end; |
| 140 |
|
| 141 |
procedure TForm1.FormPaint(Sender: TObject); |
| 142 |
var |
| 143 |
i, j: integer; |
| 144 |
begin |
| 145 |
if Image1.Picture.Width = 0 then |
| 146 |
begin |
| 147 |
Exit; |
| 148 |
end; |
| 149 |
if MyRect.Right-MyRect.Left > 500 then |
| 150 |
begin |
| 151 |
if MyRect.Right-MyRect.Left > Image1.Picture.Width+200 then |
| 152 |
begin |
| 153 |
MySize:=Image1.Picture.Width div 127; |
| 154 |
MyRect:=CalMyRect; |
| 155 |
Label2.Caption:=IntToStr(MySize); |
| 156 |
end; |
| 157 |
if (MyRect.Right-MyRect.Left+500 > Image1.Picture.Width)or |
| 158 |
(MyRect.Bottom-MyRect.Top+500 > Image1.Picture.Height) then |
| 159 |
begin |
| 160 |
Canvas.FillRect(Rect(0,0,2*350,2*350)); |
| 161 |
end; |
| 162 |
i:=MyRect.Left; |
| 163 |
j:=MyRect.Top; |
| 164 |
Canvas.CopyRect(Rect(0,0,350,350),Image1.Canvas,Rect(i-250,j-250,i+100,j+100)); |
| 165 |
i:=MyRect.Right; |
| 166 |
Canvas.CopyRect(Rect(350,0,2*350,350),Image1.Canvas, |
| 167 |
Rect(i-100,j-250,i+250,j+100)); |
| 168 |
i:=MyRect.Left; |
| 169 |
j:=MyRect.Bottom; |
| 170 |
Canvas.CopyRect(Rect(0,350,350,2*350),Image1.Canvas, |
| 171 |
Rect(i-250,j-100,i+100,j+250)); |
| 172 |
i:=MyRect.Right; |
| 173 |
Canvas.CopyRect(Rect(350,350,2*350,2*350),Image1.Canvas, |
| 174 |
Rect(i-100,j-100,i+250,j+250)); |
| 175 |
Canvas.DrawFocusRect(Rect(250,250,450,450)); |
| 176 |
end else |
| 177 |
begin |
| 178 |
i:=(Image1.Picture.Width-2*350) div 2; |
| 179 |
j:=(Image1.Picture.Height-2*350) div 2; |
| 180 |
Canvas.CopyRect(Rect(0,0,2*350,2*350),Image1.Canvas, |
| 181 |
Rect(i,j,i+2*350,j+2*350)); |
| 182 |
i:=(2*350-MyRect.Right+MyRect.Left) div 2; |
| 183 |
j:=(2*350-MyRect.Bottom+MyRect.Top) div 2; |
| 184 |
Canvas.DrawFocusRect(Rect(i,j,2*350-i,2*350-j)); |
| 185 |
end; |
| 186 |
end; |
| 187 |
|
| 188 |
function TForm1.CalMyRect: TRect; |
| 189 |
var |
| 190 |
i, j, m, n: integer; |
| 191 |
const |
| 192 |
a = 127; |
| 193 |
b = 89; |
| 194 |
begin |
| 195 |
|
| 196 |
{ |
| 197 |
case ComboBox1.ItemIndex of |
| 198 |
0: |
| 199 |
begin |
| 200 |
i:=127; |
| 201 |
j:=89; |
| 202 |
end; |
| 203 |
1: |
| 204 |
begin |
| 205 |
i:=254; |
| 206 |
j:=178; |
| 207 |
end; |
| 208 |
else |
| 209 |
i:=381; |
| 210 |
j:=267; |
| 211 |
end; |
| 212 |
} |
| 213 |
i:=MySize*a; |
| 214 |
j:=MySize*b; |
| 215 |
m:=(Image1.Picture.Width-i) div 2; |
| 216 |
n:=(Image1.Picture.Height-j) div 2; |
| 217 |
result:=Rect(m,n,m+i,n+j); |
| 218 |
|
| 219 |
end; |
| 220 |
|
| 221 |
procedure TForm1.FormCreate(Sender: TObject); |
| 222 |
begin |
| 223 |
MySize:=20; |
| 224 |
Label2.Caption:=IntToStr(MySize); |
| 225 |
Canvas.Pen.Color:=clBlue; |
| 226 |
Canvas.Pen.Width:=10; |
| 227 |
Canvas.Pen.Mode:=pmNotXor; |
| 228 |
end; |
| 229 |
|
| 230 |
procedure TForm1.SpeedButton9Click(Sender: TObject); |
| 231 |
begin |
| 232 |
if Image1.Picture.Width > MyRect.Right-MyRect.Left then |
| 233 |
begin |
| 234 |
inc(MySize); |
| 235 |
Label2.Caption:=IntToStr(MySize); |
| 236 |
MyRect:=CalMyRect; |
| 237 |
FormPaint(Sender); |
| 238 |
end; |
| 239 |
end; |
| 240 |
|
| 241 |
procedure TForm1.SpeedButton8Click(Sender: TObject); |
| 242 |
begin |
| 243 |
if MySize > 1 then |
| 244 |
begin |
| 245 |
dec(MySize); |
| 246 |
Label2.Caption:=IntToStr(MySize); |
| 247 |
MyRect:=CalMyRect; |
| 248 |
FormPaint(Sender); |
| 249 |
end; |
| 250 |
end; |
| 251 |
|
| 252 |
procedure TForm1.TrimImage; |
| 253 |
var |
| 254 |
img: TImage; |
| 255 |
begin |
| 256 |
img:=TImage.Create(Self); |
| 257 |
try |
| 258 |
img.Width:=MyRect.Right-MyRect.Left+1; |
| 259 |
img.Height:=MyRect.Bottom-MyRect.Top+1; |
| 260 |
img.Canvas.CopyRect(img.ClientRect,Image1.Canvas,MyRect); |
| 261 |
img.Picture.SaveToFile(DirectoryListBox1.GetItemPath(DirectoryListBox1.ItemIndex) |
| 262 |
+'\_'+ExtractFileName(ListBox1.Items[ListBox1.ItemIndex])); |
| 263 |
finally |
| 264 |
img.Free; |
| 265 |
end; |
| 266 |
end; |
| 267 |
|
| 268 |
procedure TForm1.SpeedButton5Click(Sender: TObject); |
| 269 |
var |
| 270 |
i: integer; |
| 271 |
begin |
| 272 |
if Sender = SpeedButton5 then |
| 273 |
begin |
| 274 |
i:=UpDown1.Position; |
| 275 |
end else |
| 276 |
begin |
| 277 |
i:=-UpDown1.Position; |
| 278 |
end; |
| 279 |
with MyRect do |
| 280 |
begin |
| 281 |
Left:=Left+i; |
| 282 |
Right:=Right+i; |
| 283 |
end; |
| 284 |
FormPaint(Sender); |
| 285 |
end; |
| 286 |
|
| 287 |
procedure TForm1.SpeedButton4Click(Sender: TObject); |
| 288 |
var |
| 289 |
i: integer; |
| 290 |
begin |
| 291 |
if Sender = SpeedButton4 then |
| 292 |
begin |
| 293 |
i:=UpDown1.Position; |
| 294 |
end else |
| 295 |
begin |
| 296 |
i:=-UpDown1.Position; |
| 297 |
end; |
| 298 |
with MyRect do |
| 299 |
begin |
| 300 |
Top:=Top-i; |
| 301 |
Bottom:=Bottom-i; |
| 302 |
end; |
| 303 |
FormPaint(Sender); |
| 304 |
end; |
| 305 |
|
| 306 |
procedure TForm1.Button3Click(Sender: TObject); |
| 307 |
begin |
| 308 |
if Image1.Picture.Width = 0 then |
| 309 |
begin |
| 310 |
Exit; |
| 311 |
end; |
| 312 |
MySize:=20; |
| 313 |
MyRect:=CalMyRect; |
| 314 |
if MyRect.Right-MyRect.Left > Image1.Picture.Width+200 then |
| 315 |
begin |
| 316 |
MySize:=Image1.Picture.Width div 127; |
| 317 |
if MySize = 0 then |
| 318 |
begin |
| 319 |
MySize:=1; |
| 320 |
end; |
| 321 |
MyRect:=CalMyRect; |
| 322 |
Label2.Caption:=IntToStr(MySize); |
| 323 |
end; |
| 324 |
FormPaint(Sender); |
| 325 |
end; |
| 326 |
|
| 327 |
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; |
| 328 |
Shift: TShiftState; X, Y: Integer); |
| 329 |
begin |
| 330 |
case Button of |
| 331 |
mbLeft: |
| 332 |
begin |
| 333 |
MouseDown:=true; |
| 334 |
DownedPos:=Point(X,Y); |
| 335 |
Gt:=Point(X,Y); |
| 336 |
Edit1.Text:='0'; |
| 337 |
FormPaint(Sender); |
| 338 |
end; |
| 339 |
mbRight: |
| 340 |
Button1Click(Button1); |
| 341 |
end; |
| 342 |
end; |
| 343 |
|
| 344 |
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, |
| 345 |
Y: Integer); |
| 346 |
var |
| 347 |
i, j: integer; |
| 348 |
begin |
| 349 |
if RadioButton1.Checked = true then |
| 350 |
begin |
| 351 |
if MouseDown = true then |
| 352 |
begin |
| 353 |
i:=X-DownedPos.X; |
| 354 |
j:=Y-DownedPos.Y; |
| 355 |
with MyRect do |
| 356 |
begin |
| 357 |
Left:=Left-i; |
| 358 |
Right:=Right-i; |
| 359 |
Top:=Top-j; |
| 360 |
Bottom:=Bottom-j; |
| 361 |
end; |
| 362 |
DownedPos:=Point(X,Y); |
| 363 |
FormPaint(Sender); |
| 364 |
end; |
| 365 |
end else |
| 366 |
begin |
| 367 |
if MouseDown = true then |
| 368 |
begin |
| 369 |
Canvas.MoveTo(DownedPos.X,DownedPos.Y); |
| 370 |
Canvas.LineTo(Gt.X,Gt.Y); |
| 371 |
Canvas.MoveTo(DownedPos.X,DownedPos.Y); |
| 372 |
Canvas.LineTo(X,Y); |
| 373 |
GT:=Point(X,Y); |
| 374 |
end; |
| 375 |
end; |
| 376 |
end; |
| 377 |
|
| 378 |
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; |
| 379 |
Shift: TShiftState; X, Y: Integer); |
| 380 |
begin |
| 381 |
if Button = mbLeft then |
| 382 |
begin |
| 383 |
MouseDown:=false; |
| 384 |
if RadioButton2.Checked = true then |
| 385 |
begin |
| 386 |
if Gt.X-DownedPos.X = 0 then |
| 387 |
begin |
| 388 |
UpDown2.Position:=90; |
| 389 |
end else |
| 390 |
begin |
| 391 |
UpDown2.Position:=Round(RadToDeg(ArcTan( |
| 392 |
-(Gt.Y-DownedPos.Y)/(Gt.X-DownedPos.X)))); |
| 393 |
end; |
| 394 |
end; |
| 395 |
end; |
| 396 |
end; |
| 397 |
|
| 398 |
procedure TForm1.Button4Click(Sender: TObject); |
| 399 |
begin |
| 400 |
Close; |
| 401 |
end; |
| 402 |
|
| 403 |
procedure TForm1.Button5Click(Sender: TObject); |
| 404 |
begin |
| 405 |
if OpenPictureDialog1.Execute and(OpenPictureDialog1.Files.Count > 0) then |
| 406 |
begin |
| 407 |
ListBox1.Items.Assign(OpenPictureDialog1.Files); |
| 408 |
ListBox1.ItemIndex:=0; |
| 409 |
Label3.Caption:=ExtractFileDir(ListBox1.Items[0]); |
| 410 |
Label3.Hint:=Label3.Caption; |
| 411 |
ListBox1Click(Sender); |
| 412 |
MyRect:=CalMyRect; |
| 413 |
FormPaint(Sender); |
| 414 |
end; |
| 415 |
end; |
| 416 |
|
| 417 |
procedure TForm1.RadioButton1Click(Sender: TObject); |
| 418 |
begin |
| 419 |
MouseDown:=false; |
| 420 |
FormPaint(Sender); |
| 421 |
end; |
| 422 |
|
| 423 |
procedure TForm1.SpeedButton1Click(Sender: TObject); |
| 424 |
var |
| 425 |
i, j, a, b: integer; |
| 426 |
m, n: integer; |
| 427 |
p: Extended; |
| 428 |
bmp: TBitmap; |
| 429 |
s, t: PRGBArray; |
| 430 |
begin |
| 431 |
i:=UpDown2.Position; |
| 432 |
if i <> 0 then |
| 433 |
begin |
| 434 |
if FileExists(Caption) = true then |
| 435 |
begin |
| 436 |
bmp:=TBitmap.Create; |
| 437 |
try |
| 438 |
bmp.PixelFormat:=pf24Bit; |
| 439 |
bmp.Assign(Image1.Picture.Graphic); |
| 440 |
Image1.Picture.Bitmap.Assign(bmp); |
| 441 |
a:=bmp.Width div 2; |
| 442 |
b:=bmp.Height div 2; |
| 443 |
p:=DegToRad(-i); |
| 444 |
for i:=0 to bmp.Height-1 do |
| 445 |
begin |
| 446 |
s:=bmp.ScanLine[i]; |
| 447 |
for j:=0 to bmp.Width-1 do |
| 448 |
begin |
| 449 |
m:=Round((j-a)*Cos(p)-(i-b)*Sin(p))+a; |
| 450 |
n:=Round((j-a)*Sin(p)+(i-b)*Cos(p))+b; |
| 451 |
if (m >= 0)and(n >= 0)and(m < bmp.Width)and(n < bmp.Height) then |
| 452 |
begin |
| 453 |
t:=Image1.Picture.Bitmap.ScanLine[n]; |
| 454 |
s[j]:=t[m]; |
| 455 |
end; |
| 456 |
end; |
| 457 |
Application.ProcessMessages; |
| 458 |
Label5.Caption:=IntToStr(100*i div bmp.Height); |
| 459 |
if SpeedButton1.Down = false then |
| 460 |
begin |
| 461 |
Exit; |
| 462 |
end; |
| 463 |
end; |
| 464 |
Image1.Picture.Bitmap.Assign(bmp); |
| 465 |
FormPaint(Sender); |
| 466 |
finally |
| 467 |
bmp.Free; |
| 468 |
end; |
| 469 |
end; |
| 470 |
end; |
| 471 |
SpeedButton1.Down:=false; |
| 472 |
end; |
| 473 |
|
| 474 |
procedure TForm1.RadioButton2Click(Sender: TObject); |
| 475 |
var |
| 476 |
s: TPicture; |
| 477 |
begin |
| 478 |
if FileExists(Caption) = true then |
| 479 |
begin |
| 480 |
s:=TPicture.Create; |
| 481 |
try |
| 482 |
s.LoadFromFile(Caption); |
| 483 |
Image1.Picture.Bitmap.Assign(s.Graphic); |
| 484 |
finally |
| 485 |
s.Free; |
| 486 |
end; |
| 487 |
FormPaint(Sender); |
| 488 |
end; |
| 489 |
end; |
| 490 |
|
| 491 |
end. |