[简单问题]用一个updown实现图象按比例缩放(20分)

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

sdralf

Unregistered / Unconfirmed
GUEST, unregistred user!
这个问题其实应该很简单的~可小弟写的代码就是实现不了~调试通过可是没有作用~大家帮小弟看看代码错在哪儿了~谢谢谢谢~

小弟原意是只要用updown1修改image1.height,让image1.width随着image1.height的增加而增加,随着减少而减少,同时将proportional定为true,这样应该就可以简单的实现图片按比例缩放了

代码如下:

//Form1中放image1,edit1,updown1
//updown1的associte指定edit1
//image1事先调入图片
procedure TForm1.UpDown5Changing(Sender: TObject;
var AllowChange: Boolean);
begin
image1.Proportional:=true;//需要保持image1.picture的比例
image1.height:=strtoint(edit1.Text);
with image1 do
if image1.Height=image1.Height+1 then image1.Width:=image1.Width+1
else if image1.Height=image1.Height-1 then image1.Width:=image1.Width-1;
end;

为什么调试通过~但在用的时候~还是只能变化image1.height而不能变image1.width~这样导致一旦image1.width达到了原来的数值~不管height怎么拉长~图片都不会再放大了~这是怎么回事啊?
 
设置Image1.Stretch:=true;
 
问一下你这两句是怎么工作的?
if image1.Height=image1.Height+1 then image1.Width:=image1.Width+1
else if image1.Height=image1.Height-1 then image1.Width:=image1.Width-1;
这句跟没写有什么不同,image1.Height 会等于image1.Height+1吗?
 
to eliphe:这没用啊~我默认设的就是TRUE~

to 野蛮人:
本为我是想实现一个递增的过程~类似i:=i+1~那如果这样不行的话那该怎么写?请指教~谢谢谢谢~
 
i:=i+1实现的是赋值功能,你怎么能用i=i+1去代替呢?
 
是啊~可是IF语句里没法用赋值~那我该怎么办?
 
刚刚看到这个问题,我试了一下,你设一个中间变量就可以,原程序如下:
interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, jpeg, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Image1: TImage;
UpDown1: TUpDown;
Edit1: TEdit;
procedure UpDown1Changing(Sender: TObject; var AllowChange: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.UpDown1Changing(Sender: TObject;
var AllowChange: Boolean);
var i:integer;
begin
image1.Proportional:=true;
i:=image1.Height;
image1.Height:=strtoint(edit1.Text);
with image1 do
if image1.Height=i+1 then image1.Width:=image1.Width+1
else if image1.Height=i-1 then image1.Width:=image1.Width-1;

end;

end.
 
FT~!偶好笨哪~这都没想到~谢谢谢谢了~
 
后退
顶部