Image 对象pascal帧内运动图像
我正在和ObjectPascal一起做一个学校项目,我正在试着做一个水果机。我试着让那个轮子转动,我得到了这张照片: 我已经到目前为止,它只显示了第一个,但我试图使图片向上移动,使它显示了其他以及。这可能吗?如果可能,如何实现 编辑:画框为100*100像素。图片为100*900像素。我希望图片移动,首先显示像素从0到100,下一步10到110,下一步20到120,等等 代码:Image 对象pascal帧内运动图像,image,delphi,Image,Delphi,我正在和ObjectPascal一起做一个学校项目,我正在试着做一个水果机。我试着让那个轮子转动,我得到了这张照片: 我已经到目前为止,它只显示了第一个,但我试图使图片向上移动,使它显示了其他以及。这可能吗?如果可能,如何实现 编辑:画框为100*100像素。图片为100*900像素。我希望图片移动,首先显示像素从0到100,下一步10到110,下一步20到120,等等 代码: unit Unit1; {$mode objfpc}{$H+} interface uses Classes
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, Crt;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
Button14: TButton;
Button15: TButton;
Button16: TButton;
Button17: TButton;
Button18: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
Image5: TImage;
Image6: TImage;
Image7: TImage;
Image8: TImage;
Image9: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Timer1: TTimer;
Timer2: TTimer;
procedure Button18Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11click(Sender: TObject);
procedure Button12click(Sender: TObject);
procedure Button13click(Sender: TObject);
procedure Button14click(Sender: TObject);
procedure Button15click(Sender: TObject);
procedure Button16click(Sender: TObject);
procedure Button17click(Sender: TObject);
procedure Timer1StopTimer(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
x1, x2, x3, x4, money: double;
s1, s2, s3, s4, Smoney: string;
meloen, pruim, citroen, banaan, zeven: TPicture;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
s4:=label3.Caption;
if s4='0' then label1.Caption:='Kies een inzet bedrag!'
else
begin
Smoney:=label2.Caption;
money:=StrToFloat(Smoney);
x4:=StrToFloat(s4);
if x4>money then label1.Caption:='Uw inzet is te hoog!'
else
begin
money:=money-x4;
Smoney:=FloatToStr(money);
label2.Caption:=Smoney;
image1.Picture.LoadFromFile('rol2.png');
image2.Picture.LoadFromFile('rol2.png');
image3.Picture.LoadFromFile('rol2.png');
image4.Picture.LoadFromFile('rol1.png');
image5.Picture.LoadFromFile('rol2.png');
image6.Picture.LoadFromFile('rol3.png');
image7.Picture.LoadFromFile('rol1.png');
image8.Picture.LoadFromFile('rol2.png');
image9.Picture.LoadFromFile('rol3.png');
timer1.Enabled:=true;
end;
end;
end;
procedure TForm1.Button18Click(Sender: TObject);
begin
label1.Caption:='';
label2.Caption:='100';
label3.Caption:='0';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
label3.Caption:='1';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
label3.Caption:='2';
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
label3.Caption:='3';
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
label3.Caption:='4';
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
label3.Caption:='5';
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
label3.Caption:='10';
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
label3.Caption:='20';
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
label3.Caption:='25';
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
label3.Caption:='50';
end;
procedure TForm1.Button11Click(Sender: TObject);
begin
label3.Caption:='75';
end;
procedure TForm1.Button12Click(Sender: TObject);
begin
label3.Caption:='100';
end;
procedure TForm1.Button13Click(Sender: TObject);
begin
label3.Caption:='200';
end;
procedure TForm1.Button14Click(Sender: TObject);
begin
label3.Caption:='250';
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
label3.Caption:='500';
end;
procedure TForm1.Button16Click(Sender: TObject);
begin
label3.Caption:='750';
end;
procedure TForm1.Button17Click(Sender: TObject);
begin
label3.Caption:='1000';
end;
procedure TForm1.Timer1StopTimer(Sender: TObject);
begin
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
x1:=random(2);
x2:=random(5);
x3:=random(5);
if x1=1 then begin
image1.Picture.LoadFromFile('kers.png');
image4.Picture.LoadFromFile('meloen.png');
image7.Picture.LoadFromFile('zeven.png');
end;
if x1=2 then begin
image1.Picture.LoadFromFile('meloen.png');
image4.Picture.LoadFromFile('zeven.png');
image7.Picture.LoadFromFile('citroen.png');
end;
if x1=3 then begin
image1.Picture.LoadFromFile('zeven.png');
image4.Picture.LoadFromFile('citroen.png');
image7.Picture.LoadFromFile('banaan.png');
end;
if x1=4 then begin
image1.Picture.LoadFromFile('citroen.png');
image4.Picture.LoadFromFile('banaan.png');
image7.Picture.LoadFromFile('pruim.png');
end;
if x1=5 then begin
image1.Picture.LoadFromFile('banaan.png');
image4.Picture.LoadFromFile('pruim.png');
image7.Picture.LoadFromFile('big.png');
end;
if x1=6 then begin
image1.Picture.LoadFromFile('pruim.png');
image4.Picture.LoadFromFile('big.png');
image7.Picture.LoadFromFile('bar.png');
end;
if x1=7 then begin
image1.Picture.LoadFromFile('big.png');
image4.Picture.LoadFromFile('bar.png');
image7.Picture.LoadFromFile('sinaas.png');
end;
if x1=8 then begin
image1.Picture.LoadFromFile('bar.png');
image4.Picture.LoadFromFile('sinaas.png');
image7.Picture.LoadFromFile('kers.png');
end;
if x1=9 then begin
image1.Picture.LoadFromFile('sinaas.png');
image4.Picture.LoadFromFile('kers.png');
image7.Picture.LoadFromFile('meloen.png');
end;
if x2=1 then begin
image2.Picture.LoadFromFile('kers.png');
image5.Picture.LoadFromFile('meloen.png');
image8.Picture.LoadFromFile('zeven.png');
end;
if x2=2 then begin
image2.Picture.LoadFromFile('meloen.png');
image5.Picture.LoadFromFile('zeven.png');
image8.Picture.LoadFromFile('citroen.png');
end;
if x2=3 then begin
image2.Picture.LoadFromFile('zeven.png');
image5.Picture.LoadFromFile('citroen.png');
image8.Picture.LoadFromFile('banaan.png');
end;
if x2=4 then begin
image2.Picture.LoadFromFile('citroen.png');
image5.Picture.LoadFromFile('banaan.png');
image8.Picture.LoadFromFile('pruim.png');
end;
if x2=5 then begin
image2.Picture.LoadFromFile('banaan.png');
image5.Picture.LoadFromFile('pruim.png');
image8.Picture.LoadFromFile('big.png');
end;
if x2=6 then begin
image2.Picture.LoadFromFile('pruim.png');
image5.Picture.LoadFromFile('big.png');
image8.Picture.LoadFromFile('bar.png');
end;
if x2=7 then begin
image2.Picture.LoadFromFile('big.png');
image5.Picture.LoadFromFile('bar.png');
image8.Picture.LoadFromFile('sinaas.png');
end;
if x2=8 then begin
image2.Picture.LoadFromFile('bar.png');
image5.Picture.LoadFromFile('sinaas.png');
image8.Picture.LoadFromFile('kers.png');
end;
if x2=9 then begin
image2.Picture.LoadFromFile('sinaas.png');
image5.Picture.LoadFromFile('kers.png');
image8.Picture.LoadFromFile('meloen.png');
end;
if x3=1 then begin
image3.Picture.LoadFromFile('kers.png');
image6.Picture.LoadFromFile('meloen.png');
image9.Picture.LoadFromFile('zeven.png');
end;
if x3=2 then begin
image3.Picture.LoadFromFile('meloen.png');
image6.Picture.LoadFromFile('zeven.png');
image9.Picture.LoadFromFile('citroen.png');
end;
if x3=3 then begin
image3.Picture.LoadFromFile('zeven.png');
image6.Picture.LoadFromFile('citroen.png');
image9.Picture.LoadFromFile('banaan.png');
end;
if x3=4 then begin
image3.Picture.LoadFromFile('citroen.png');
image6.Picture.LoadFromFile('banaan.png');
image9.Picture.LoadFromFile('pruim.png');
end;
if x3=5 then begin
image3.Picture.LoadFromFile('banaan.png');
image6.Picture.LoadFromFile('pruim.png');
image9.Picture.LoadFromFile('big.png');
end;
if x3=6 then begin
image3.Picture.LoadFromFile('pruim.png');
image6.Picture.LoadFromFile('big.png');
image9.Picture.LoadFromFile('bar.png');
end;
if x3=7 then begin
image3.Picture.LoadFromFile('big.png');
image6.Picture.LoadFromFile('bar.png');
image9.Picture.LoadFromFile('sinaas.png');
end;
if x3=8 then begin
image3.Picture.LoadFromFile('bar.png');
image6.Picture.LoadFromFile('sinaas.png');
image9.Picture.LoadFromFile('kers.png');
end;
if x3=9 then begin
image3.Picture.LoadFromFile('sinaas.png');
image6.Picture.LoadFromFile('kers.png');
image9.Picture.LoadFromFile('meloen.png');
end;
if (x1=x2) and (x2=x3) then
begin
x4:=x4*10;
money:=StrToFloat(Smoney);
money:=money+x4;
Smoney:=FloatToStr(money);
label2.caption:=Smoney;
x4:=x4/4;
end
else if (x1=x2) xor (x2=x3) xor (x1=x3) then
begin
x4:=x4*3;
money:=StrToFloat(Smoney);
money:=money+x4;
Smoney:=FloatToStr(money);
label2.caption:=Smoney;
x4:=x4/2;
end;
timer1.Enabled:=false;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var
i:integer;
y:double;
begin
image1.Picture.LoadFromFile('rol.png');
end;
end.
您可以将100x900图像加载到TBitmap中,然后使用图像的Canvas属性和画布的CopyRect方法将位图中的任何矩形绘制到画布上。例如,如果您的位图加载到FFruit中,并且您对位图中的行使用FPO(例如,第三张图片将从200开始): 您可以在计时器事件中执行此操作,也可以在其中更新FPO
对您当前发布的代码的一个批评是:不要在计时器中调用LoadFromFile方法。将图像加载到TBitmaps中一次,然后在计时器中分配它们。LoadFromFile需要大量磁盘读取和处理。您可以将100x900图像加载到TBitmap中,然后使用图像的Canvas属性和画布的CopyRect方法将位图中的任何矩形绘制到画布。例如,如果您的位图加载到FFruit中,并且您对位图中的行使用FPO(例如,第三张图片将从200开始): 您可以在计时器事件中执行此操作,也可以在其中更新FPO
对您当前发布的代码的一个批评是:不要在计时器中调用LoadFromFile方法。将图像加载到TBitmaps中一次,然后在计时器中分配它们。LoadFromFile需要大量的磁盘读取和处理。我已经修复了它。把照片放在后面就行了。无法加载gif。。无法在中获取视频。。。别无选择。。也许有更多的图片,它看起来更好,但它的工作现在。谢谢你的帮助我已经修好了。把照片放在后面就行了。无法加载gif。。无法在中获取视频。。。别无选择。。也许有更多的图片,它看起来更好,但它的工作现在。谢谢所有的帮助这是我一直在寻找的!这就是我一直在寻找的!
Image1.Canvas.CopyRect(Rect(0, 0, 100, 100), FFruit.Canvas, Rect(0, FPos, 100, FPos+100));