gridview - Draw TBitmaps in DrawGrid in Delphi -
i have 8 x 16 drawgrid in delphi xe5 randomly fill 9 images i've stored in c:\users\sean ewing\documents\my documents\delphi tutorials\other\math-o-sphere\win32\debug\img. i'm trying 1 image load make sure i'm doing correctly. here code i've used this:
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;
the code compiles fine, , based on i've read in embarcadero wiki correct, error @ runtime when it's time load drawggrid. did go wrong?
you need first create bitmap before can use it:
procedure tform1.grdplayfielddrawcell(sender: tobject; acol, arow: integer; rect: trect; state: tgriddrawstate); var sphereplus: tbitmap; begin sphereplus := tbitmap.create; try sphereplus.loadfromfile(extractfilepath(application.exename) + '\img\sphere +1.bmp'); grdplayfield.canvas.draw(0, 0, sphereplus); sphereplus.free; end; end;
the other thing should aware of rect
parameter receive in event area needs painted, you'll want use canvas.stretchdraw
, pass rectangle. won't current issue, you'll need when move next step. can identify exact cell that's being drawn acol
, arow
parameters, can use information load specific image column, instance, or output text column or row.
// load specific image cell passed in acol , arow, // , draw appropriate area using rect provided. grdplayfield.canvas.stretchdraw(rect, sphereplus);
Comments
Post a Comment