{
关键字=图片等比例值缩放
采集软件=MKM - 我的知识管理
采集日期=2023-11-23 14:23:08
数字签名=220D2317D8B6BF15948214A98BFE24EA
}
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
uses
math;
procedure TForm1.Button1Click(Sender: TObject);
var
Zoom: Extended;
W, H: integer;
bmp: Tbitmap;
begin
{图片等比例值缩放
}
bmp := Tbitmap.Create;
bmp.LoadFromFile(‘d:\vlc\1.bmp’);
Zoom := Image1.Width / Max(bmp.Width, bmp.Height); //获得比例值
W := Trunc(bmp.Width * Zoom);
H := Trunc(bmp.Height * Zoom);
//居中显示缩小后的图片
Image1.Canvas.StretchDraw(Rect(Trunc((Image1.width - W) / 2), Trunc((Image1.Height - H) / 2), Trunc((Image1.width - W) / 2) + W, Trunc((Image1.Height - H) / 2) + H), Bmp);
bmp.free;
end;