【发布时间】:2014-05-24 20:59:53
【问题描述】:
我在 Delphi XE5 中有一个 8 x 16 DrawGrid,我想用我存储在 C:\Users\Sean Ewing\Documents\My Documents\Delphi Tutorials\Other\Math 中的九个图像随机填充它-O-Sphere\Win32\Debug\img。我目前正在尝试加载一张图片以确保我做得正确。这是我用来执行此操作的代码:
procedure TForm1.grdPlayFieldDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
spherePlus: TBitmap;
begin
spherePlus.LoadFromFile(ExtractFilePath(Application.ExeName) + '\img\Sphere +1.bmp');
grdPlayField.Canvas.Draw(0, 0, spherePlus);
end;
代码编译良好,根据我在 Embarcadero wiki 中阅读的内容,这是正确的,但在加载 DrawGgrid 时,我在运行时遇到错误。我哪里做错了?
【问题讨论】:
-
你忘记了
spherePlus := TBitmap.Create。你买的是AV吧?当您提出问题时,不要忘记说明您遇到了什么错误,以及在哪里出错。 -
只加载一次位图。不是每次你都要画画。