如何在界面上移动图片?试了一下,感觉:
1、程序控制TImage控件的话比较好操作,但是cpu占用率太多,达50%。看某些网页上的图片漂浮移动,基本不太占用cpu,不知道是怎么做的。所以我想delphi也应该可以; 但问题是怎么做? 2、用画的办法把图片重新绘制或者拷贝到显示区域,发现cpu就不是太占用了。
但是不太好控制,我想是我没用掌握这个方法。 望高手指教;关键是如何擦除原来绘制的图片内容,还原为背景;
1、程序控制TImage控件的话比较好操作,但是cpu占用率太多,达50%。看某些网页上的图片漂浮移动,基本不太占用cpu,不知道是怎么做的。所以我想delphi也应该可以; 但问题是怎么做? 2、用画的办法把图片重新绘制或者拷贝到显示区域,发现cpu就不是太占用了。
但是不太好控制,我想是我没用掌握这个方法。 望高手指教;关键是如何擦除原来绘制的图片内容,还原为背景;
http://www.codeidea.com/cn/
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons;type
TForm1 = class(TForm)
Panel1: TPanel;
Image1: TImage;
B_up: TBitBtn;
B_down: TBitBtn;
B_left: TBitBtn;
B_right: TBitBtn;
procedure B_upClick(Sender: TObject);
procedure B_downClick(Sender: TObject);
procedure B_leftClick(Sender: TObject);
procedure B_rightClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
bmp: TBitmap;
bmpwidth,bmpheight: integer; //图片的宽度和高度
implementation{$R *.dfm}procedure TForm1.B_upClick(Sender: TObject);
var
i:integer;
begin
bmp:=TBitmap.Create;
bmp.Width:=Image1.Width;
bmp.Height:=Image1.Height;
bmpwidth:=Image1.Width;
bmpheight:=Image1.Height;
Image1.Visible:=False;
for i:=0 to bmpheight do
begin
bmp.Canvas.CopyRect(Rect(0,bmpheight-i,bmpwidth,bmpheight),image1.Canvas,
Rect(0,0,bmpwidth,i)); //上拉效果
Form1.Canvas.Draw(16,16,bmp); //在坐标(16,16)处显示位图
end;
bmp.Free;
Image1.Visible:=True;
end;procedure TForm1.B_downClick(Sender: TObject);
var
i:integer;
begin
bmp:=TBitmap.Create;
bmp.Width:=Image1.Width;
bmp.Height:=Image1.Height;
bmpwidth:=Image1.Width;
bmpheight:=Image1.Height;
Image1.Visible:=False;
for i:=0 to bmpheight do
begin
bmp.Canvas.CopyRect(Rect(0,0,bmpwidth,i),image1.Canvas,
Rect(0,bmpheight-i,bmpwidth,bmpheight)); //下拉效果
Form1.Canvas.Draw(16,16,bmp); //在坐标(16,16)处显示位图
end;
bmp.Free;
Image1.Visible:=True;
end;procedure TForm1.B_leftClick(Sender: TObject);
var
i:integer;
begin
bmp:=TBitmap.Create;
bmp.Width:=Image1.Width;
bmp.Height:=Image1.Height;
bmpwidth:=Image1.Width;
bmpheight:=Image1.Height;
Image1.Visible:=False;
for i:=0 to bmpwidth do
begin
bmp.Canvas.CopyRect(Rect(bmpwidth-i,0,bmpwidth,bmpheight),image1.Canvas,
Rect(0,0,i,bmpheight)); //左移效果
Form1.Canvas.Draw(16,16,bmp); //在坐标(16,16)处显示位图
end;
bmp.Free;
Image1.Visible:=True;
end;procedure TForm1.B_rightClick(Sender: TObject);
var
i:integer;
begin
bmp:=TBitmap.Create;
bmp.Width:=Image1.Width;
bmp.Height:=Image1.Height;
bmpwidth:=Image1.Width;
bmpheight:=Image1.Height;
Image1.Visible:=False;
for i:=0 to bmpwidth do
begin
bmp.Canvas.CopyRect(Rect(0,0,i,bmpheight),image1.Canvas,
Rect(bmpwidth-i,0,bmpwidth,bmpheight)); //右移效果
Form1.Canvas.Draw(16,16,bmp); //在坐标(16,16)处显示位图
end;
bmp.Free;
Image1.Visible:=True;
end;end.
加个timer时间间隔多少就可以实现你说的问题