怎么样让图片向框体中间缩放(50分)

  • 主题发起人 主题发起人 lwsi
  • 开始时间 开始时间
L

lwsi

Unregistered / Unconfirmed
GUEST, unregistred user!
我做图片的缩放,让宽高为原来的一半或加一倍
如下面放大:
image1.Height:=image1.Height * 2;
image1.Width:=image1.Width * 2;
这样都向那张图的左上角缩放,怎么样使它向中
间缩放呢?像ACDsee那里一样
 
要图片向中间缩放,那该IMAGE的中心位置是不变的,应该先确定框体(IMAGE)的中心位置,
然后根据该位置,每次调整IMAGE的宽高后,相应的修改IMAGE的TOP,LEFT属性。
 
image的位置确定一下,或者用stretchdraw(Rect,bmp)来缩放,自己确定一下
rect的位置这样比较简单!
 
你只要用下用代码就可以的了.
image1.Left:=image1.Left+trunc((image1.Width)/2)-image1.Width;
image1.Top:=image1.Top+trunc((image1.Height)/2)-image1.Height;
image1.Height:=image1.Height * 2;
image1.Width:=image1.Width * 2;
 
朋友,将TImage 的
Stretch属性设置为
true
试一下吧!
 
谢谢各位的帮助,看我写的缩放的实现,有些奇怪,我以为放大时应
该减去1/4宽度的,但这样的话图片就往右下移了怎么会这样?
(有个问题是:如果缩得太小的话再变大就会变形了,加个限制条件应该可以了):
//缩小
procedure TForm3.SpeedButton1Click(Sender: TObject);
begin
image1.AutoSize:=false;
image1.Stretch:=true;
image1.Left:=image1.Left+trunc((image1.Width)/4);
image1.Top:=image1.Top+trunc((image1.Height)/4);
image1.Height:=image1.Height div 2;
image1.Width:=image1.Width div 2;
end;

//放大
procedure TForm3.SpeedButton2Click(Sender: TObject);
begin
image1.AutoSize:=false;
image1.Stretch:=true;
image1.Left:=image1.Left-trunc((image1.Width)/2);
image1.Top:=image1.Top-trunc((image1.Height)/2);
image1.Height:=image1.Height * 2;
image1.Width:=image1.Width * 2;
end;
 
接受答案了.
 
后退
顶部