呵呵,看到你看着代码都搞不清的样子,我是连代码都不敢写给你了,好好的代码,到了
你手里不知会变出什么问题,这是最后一次,以后我是再也不敢没弄清编程能力就写代码
了。
下面我帖的是完整的一个平滑滚动代码,是最最最最简单的了,你再弄不好,我也没法子
了,写这个代码时,我是把你的编程能力都考虑进去了:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TDirParam=(dpTop,dpBottom,dpRight,dpLeft);
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Button2: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
DupBmp:TBitmap;
Bmp:TBitmap;
OldTop,OldLeft:integer;
ImageW,ImageH:integer;
Dir:TDirParam;
Speed:integer;
NoBusy:Boolean;
procedure InitParam;
procedure DuplicateImage(Image:TImage);
procedure Start;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// 警告:Image1 中只能装入 BMP 格式的图片
procedure TForm1.InitParam;
begin // 初始化参数
OldTop:=0;OldLeft:=0;
ImageW:=Image1.Picture.Bitmap.Width;
ImageH:=Image1.Picture.Bitmap.Height div 5;
Dir:=dpTop; // 平滑滚动的方向
Speed:=1; // 平滑滚动的速度
if not Assigned(Bmp) then
Bmp:=TBitmap.Create;
Bmp.Width:=ImageW;
Bmp.Height:=ImageH;
Bmp.PixelFormat:=pf32Bit;
end;
procedure TForm1.DuplicateImage(Image: TImage);
begin // 保存原始图片
if not Assigned(DupBmp) then
begin
DupBmp:=TBitmap.Create;
DupBmp.Assign(Image1.Picture.Bitmap);
DupBmp.PixelFormat:=pf32bit;
Image.AutoSize:=False;
Image.SetBounds(0,0,ImageW,ImageH);
end;
end;
procedure TForm1.Start;
type // 平滑滚动计算
TRGBQuadarray = array[0..0] of TRGBQuad;
pRGBQuadArray = ^TRGBQuadArray;
var
A,B
RGBQuadArray;
n,m:integer;
begin
if not NoBusy then exit;
NoBusy:=False;
case Dir of // 维度限制计算
dpTop:if (OldTop+ImageH)>DupBmp.Height then OldTop:=DupBmp.Height-ImageH;
dpBottom:if OldTop<0 then OldTop:=0;
dpLeft:if (OldLeft+ImageW)>DupBmp.Width then OldLeft:=DupBmp.Width-ImageW;
dpRight:if OldLeft<0 then OldLeft:=0;
end;
for n:=OldTop to OldTop+ImageH-1 do
begin
A := DupBmp.ScanLine[n];
B := Bmp.ScanLine[n-OldTop];
for m:=OldLeft to OldLeft+ImageW-1 do
B^[m-OldLeft]:=A^[m];
end;
Image1.Picture.Bitmap.Assign(Bmp);
Image1.Refresh; // 刷新
Application.ProcessMessages;
case Dir of // 增减维度计算
dpTop:Inc(OldTop,Speed);
dpBottom
ec(OldTop,Speed);
dpLeft
ec(OldLeft,Speed);
dpRight:Inc(OldLeft,Speed);
end;
NoBusy:=True;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin // 定时器
if NoBusy then Start;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin // 开始
InitParam;
DuplicateImage(Image1);
NoBusy:=True;
Timer1.Interval:=100;
Timer1.Enabled:=True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin // 停止
Timer1.Enabled:=False;
NoBusy:=False;
Image1.Picture.Assign(DupBmp);
Image1.AutoSize:=True;
InitParam;
end;
end.