Урок 80 - Масштабирование рисунка


задание на delphi. Растягиваем рисунок сохраняя пропорции

unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Samples.Spin;
type
TForm1 = class(TForm)
Button1: TButton;
SpinEdit1: TSpinEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
bmp1,bmp2:TBitmap;
R: TRect;
begin
bmp1:=TBitmap.Create;
bmp1.LoadFromFile('..\..\football.bmp');
bmp2:=TBitmap.Create;
bmp2.Height:=SpinEdit1.Value;
bmp2.Width:=SpinEdit1.Value;
R.Left:=0; R.Top:=0; R.Right:=SpinEdit1.Value; R.Bottom:=SpinEdit1.Value;
bmp2.Canvas.StretchDraw(r,bmp1);
bmp2.SaveToFile(IntToStr(Button1.tag)+'.bmp');
Button1.Tag:=Button1.Tag+1;
FreeAndNil(bmp1);
FreeAndNil(bmp2);
end;
end.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Samples.Spin;
type
TForm1 = class(TForm)
Button1: TButton;
SpinEdit1: TSpinEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
bmp1,bmp2:TBitmap;
R: TRect;
begin
bmp1:=TBitmap.Create;
bmp1.LoadFromFile('..\..\football.bmp');
bmp2:=TBitmap.Create;
bmp2.Height:=SpinEdit1.Value;
bmp2.Width:=SpinEdit1.Value;
R.Left:=0; R.Top:=0; R.Right:=SpinEdit1.Value; R.Bottom:=SpinEdit1.Value;
bmp2.Canvas.StretchDraw(r,bmp1);
bmp2.SaveToFile(IntToStr(Button1.tag)+'.bmp');
Button1.Tag:=Button1.Tag+1;
FreeAndNil(bmp1);
FreeAndNil(bmp2);
end;
end.