求助:用IMAGE加载一个图像,如何做到自动缩放不变形? ( 积分: 30 )

  • 主题发起人 主题发起人 sxwy
  • 开始时间 开始时间
S

sxwy

Unregistered / Unconfirmed
GUEST, unregistred user!
现在想用一个长256像素,高:64像素的IMAGE去加载一个长1024像素,高768像素的BMP图片,如何能让这个大的图片完全显示在IMAGE里,而且不变形.请各位大虾帮忙.
 
现在想用一个长256像素,高:64像素的IMAGE去加载一个长1024像素,高768像素的BMP图片,如何能让这个大的图片完全显示在IMAGE里,而且不变形.请各位大虾帮忙.
 
procedure TForm1.FormCreate(Sender: TObject);
begin
image1.SetBounds(image1.Left,image1.Top,250,64);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
bmp:Tbitmap;
tmp:single;
w,h:integer;
begin
bmp:=Tbitmap.Create;
bmp.Width:=1024;
bmp.Height:=768;
bmp.LoadFromFile('d:/28.bmp');//加载1024*768的图象
tmp:=image1.Width / bmp.Width;
if tmp * bmp.Height>image1.Height then
begin
w:=bmp.Width * image1.Height div bmp.Height;
h:=image1.Height;
end
else
begin
w:=image1.Width;
h:=bmp.Height * image1.width div bmp.width;
end;
bmp.Canvas.StretchDraw(rect(0,0,w,h),bmp);
image1.Picture.Assign(bmp);
bmp.Free;
end;
 
设置一下autosize就可以了
 
Proportional属性就是保持比例。
 
東蘭說得沒錯呀
 
多人接受答案了。
 
后退
顶部