Delphi image 等比例缩小

时间:2021-01-01 11:59:30   收藏:0   阅读:0
//等比例缩小
uses Math;
var
Zoom:Extended;
W,H:integer;
bmp:Tbitmap;
begin
  bmp:=Tbitmap.Create;
  bmp.LoadFromFile(c:\aa.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;

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!