-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDelphi_Image_Resize
66 lines (62 loc) · 1.77 KB
/
Delphi_Image_Resize
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
procedure ResizeIm(Original, Output : TBitmap; W, H : Integer);
var
buffer: TBitmap;
begin
buffer := TBitmap.Create;
try
buffer.SetSize(W, H);
buffer.Canvas.StretchDraw(Rect(0, 0, W, H), Original);
Output.SetSize(W, H);
Output.Canvas.Draw(0, 0, buffer);
finally
buffer.Free;
end;
end;
procedure TForm1.FormResize(Sender: TObject);
var
W, H : integer;
begin
if (ScrollBox1.Width < OriginalImage.Width) or (ScrollBox1.Height < OriginalImage.Height) then
begin
if (OriginalImage.Height > ScrollBox1.Height) and (OriginalImage.Width > ScrollBox1.Width) then
begin
if ScrollBox1.Height > ScrollBox1.Width then
begin
H := ScrollBox1.Height - 10;
repeat
H := H - 10;
W := Round (h * (OriginalImage.Width / OriginalImage.Height));
until W < ScrollBox1.Width - 10;
ResizeIm(OriginalImage, Image1.Picture.Bitmap, W, H);
end
else
begin
W := ScrollBox1.Width - 10;
repeat
W := W - 10;
H := Round (w * (OriginalImage.Height / OriginalImage.Width));
until H < ScrollBox1.Height - 10;
ResizeIm(OriginalImage, Image1.Picture.Bitmap, W, H);
end;
exit;
end;
if (OriginalImage.Height > ScrollBox1.Height) then
begin
H := ScrollBox1.Height - 10;
W := Round (h * (OriginalImage.Width / OriginalImage.Height));
ResizeIm(OriginalImage, Image1.Picture.Bitmap, W, H);
exit;
end;
if (OriginalImage.Width > ScrollBox1.Width) then
begin
W := ScrollBox1.Width - 10;
H := Round (w * (OriginalImage.Height / OriginalImage.Width));
ResizeIm(OriginalImage, Image1.Picture.Bitmap, W, H);
exit;
end;
end
else
begin
Image1.Picture.Assign(OriginalImage);
end;
end;