Масштабирование картинки по ширине или высоте
Автор: Шляхов Георгий
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, jpeg;
type
TForm1 = class(TForm)
Image1: TImage;
Edit1: TEdit;
Button1: TButton;
Bevel1: TBevel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
Height, Width: integer;
HH, WW: real;
begin
Height := 329;
Width := 329;
Image1.Picture.LoadFromFile(edit1.Text);
Image1.AutoSize := true;
Image1.AutoSize := false;
HH := Image1.Height / Height;
WW := Image1.Width / Width;
if (HH > WW) then
begin
Image1.Height := trunc(Image1.Height / HH);
Image1.Width := trunc(Image1.Width / HH);
Image1.Stretch := True;
//ShowMessage('По высоте');
end
else
begin
Image1.Height := trunc(Image1.Height / WW);
Image1.Width := trunc(Image1.Width / WW);
Image1.Stretch := True;
//ShowMessage('По ширине');
end;
end;
end.
|