大侠帮忙,如何改变Image控件中图片的大小,并任意拖动显示图片?

windofsun 2002-06-14 02:24:26
在Image控件大小固定的情况下,要按照用户操作放大或缩小图片。当图片不能全部显示出来时,用户可以用鼠标拖动图片,任意调整被显示的部分。就象ACDSee一样,当图片不能完全显示时用户可以拖动图片。各位大侠,帮帮忙!

注意!Image控件的大小和位置都是固定的
...全文
149 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
surfguy 2002-06-14
  • 打赏
  • 举报
回复
to: zhhahuatian(华仔),那是帮主,不用怕,他跑不掉的,有什么问题来这里就行了。
zhhahuatian 2002-06-14
  • 打赏
  • 举报
回复
楼上的很利害,qq是多少
王集鹄 2002-06-14
  • 打赏
  • 举报
回复
具体的一些处理就由你自己来完成,唉~谁叫你老板不发工资给俺 :(
王集鹄 2002-06-14
  • 打赏
  • 举报
回复

Image1.AutoSize := True; //让图片控件和图片区域保持一样的大小
Image1.AutoSize := False; //恢复以前的状态,否则怎么改变它的大小?
windofsun 2002-06-14
  • 打赏
  • 举报
回复
伴水:

Image1.AutoSize := True;
Image1.AutoSize := False;
这两句有什么作用?
FlyingQQ 2002-06-14
  • 打赏
  • 举报
回复
哇!
老师,你怎么把窗体文件也贴出来了!
楼主,我老师的回答是正确的,我试过啦!
:)
(回答问题的过程: zswang(伴水) 老师写代码,FlyingQQ(FlyingQQ)测试)
嘻嘻嘻嘻嘻嘻嘻嘻嘻
嘻嘻嘻通过!嘻嘻嘻
嘻嘻嘻嘻嘻嘻嘻嘻嘻
smhpnuaa 2002-06-14
  • 打赏
  • 举报
回复
image1.Stretch:=True;

拖动的时候要注意边界检测,不能无限拖下去。
王集鹄 2002-06-14
  • 打赏
  • 举报
回复
//不要复制注释
//请参考
//Unit1.dfm

object Form1: TForm1
Left = 192
Top = 107
Width = 426
Height = 411
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 0
Top = 41
Width = 418
Height = 343
Align = alClient
TabOrder = 0
object Image1: TImage
Left = 64
Top = 64
Width = 281
Height = 217
DragCursor = crUpArrow
Stretch = True
OnClick = Image1Click
OnMouseDown = Image1MouseDown
OnMouseMove = Image1MouseMove
OnMouseUp = Image1MouseUp
end
end
object Panel2: TPanel
Left = 0
Top = 0
Width = 418
Height = 41
Align = alTop
TabOrder = 1
object RadioButton3: TRadioButton
Left = 224
Top = 8
Width = 82
Height = 17
Caption = '缩小'
TabOrder = 0
OnClick = RadioButton3Click
end
object RadioButton2: TRadioButton
Left = 128
Top = 8
Width = 82
Height = 17
Caption = '放大'
TabOrder = 1
OnClick = RadioButton2Click
end
object RadioButton1: TRadioButton
Left = 24
Top = 8
Width = 82
Height = 17
Caption = '拖动'
Checked = True
TabOrder = 2
TabStop = True
OnClick = RadioButton1Click
end
object Button1: TButton
Left = 336
Top = 8
Width = 75
Height = 25
Caption = '载入图片'
TabOrder = 3
OnClick = Button1Click
end
end
object OpenPictureDialog1: TOpenPictureDialog
Left = 8
Top = 16
end
object Database1: TDatabase
SessionName = 'Default'
Left = 8
Top = 48
end
end

//Unit1.pas
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ExtDlgs, DB, DBTables;

type
TForm1 = class(TForm)
Panel1: TPanel;
Image1: TImage;
OpenPictureDialog1: TOpenPictureDialog;
Database1: TDatabase;
Panel2: TPanel;
RadioButton3: TRadioButton;
RadioButton2: TRadioButton;
RadioButton1: TRadioButton;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure Image1Click(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure RadioButton3Click(Sender: TObject);
private
{ Private declarations }
FMouseDown: Boolean;
FOldPoint: TPoint;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if not OpenPictureDialog1.Execute then Exit;
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
Image1.AutoSize := True;
Image1.AutoSize := False;
Image1.Left := 0;
Image1.Top := 0;
end;

procedure TForm1.Image1Click(Sender: TObject);
const
cOffset = 50;
begin
if RadioButton2.Checked then begin //放大
Image1.Width := Image1.Width + cOffset;
Image1.Height := Image1.Height + cOffset;
Exit;
end;
if RadioButton3.Checked then begin //放大
Image1.Width := Image1.Width - cOffset;
Image1.Height := Image1.Height - cOffset;
Exit;
end;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FMouseDown := Button = mbLeft;
FOldPoint := Point(X, Y);
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FMouseDown := False;
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if not FMouseDown then Exit;
if not RadioButton1.Checked then Exit;
Image1.Left := Image1.Left + (X - FOldPoint.X);
Image1.Top := Image1.Top + (Y - FOldPoint.Y);
end;

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
Image1.Cursor := crHandPoint;
end;

procedure TForm1.RadioButton2Click(Sender: TObject);
begin
Image1.Cursor := crCross;
end;

procedure TForm1.RadioButton3Click(Sender: TObject);
begin
Image1.Cursor := crUpArrow;
end;

end.
taxi 2002-06-14
  • 打赏
  • 举报
回复
在鼠标事件中自己改变image的位置就可以了。
netlib 2002-06-14
  • 打赏
  • 举报
回复
image1.Stretch:=True;

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧