mathes
asked on
drawgrid component
Hi experts,
I want to display 64 bitmaps in a 8x8 grid. Now I am searching for the right component. I am thinking of using a DrawGrid, but I am not sure if this is the right idea.
Unfortunately there is no valid statement like
drawgrid1.row1.col1.LoadFr omFile:="c :\mybitmap 1.bmp";
drawgrid1.row1.col2.LoadFr omFile:="c :\mybitmap 2.bmp";
....
drawgrid1.row8.col8.LoadFr omFile:="c :\mybitmap 64.bmp";
How would you solve this problem?
I want to display 64 bitmaps in a 8x8 grid. Now I am searching for the right component. I am thinking of using a DrawGrid, but I am not sure if this is the right idea.
Unfortunately there is no valid statement like
drawgrid1.row1.col1.LoadFr
drawgrid1.row1.col2.LoadFr
....
drawgrid1.row8.col8.LoadFr
How would you solve this problem?
Hello,
If your images are the same size then you could try storing them in an imagelist. Then in the OnDrawCell event you could calculate an index and draw the appropriate image on the drawgrid. eg :
procedure TForm1.DrawGrid1DrawCell(S ender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
intIndex:integer;
bmpTemp:TBitmap;
begin
intIndex := (ACol * 8) + ARow; // calculate an index
bmpTemp:=TBitmap.Create;
try
imagelist1.getbitmap(intIn dex,bmpTem p); // get bitmap from imagelist
DrawGrid1.Canvas.StretchDr aw(Rect,bm pTemp); // draw the bitmap to fill the contents of the cell
finally
bmpTemp.Free; // free up temporary bitmap afterwards
end;
end;
To prevent stretching of the bitmaps just set the DefaultRowHeight and DefaultColumnWidth to the same dimensions of your bitmaps.
Hope this helps
Jo
If your images are the same size then you could try storing them in an imagelist. Then in the OnDrawCell event you could calculate an index and draw the appropriate image on the drawgrid. eg :
procedure TForm1.DrawGrid1DrawCell(S
Rect: TRect; State: TGridDrawState);
var
intIndex:integer;
bmpTemp:TBitmap;
begin
intIndex := (ACol * 8) + ARow; // calculate an index
bmpTemp:=TBitmap.Create;
try
imagelist1.getbitmap(intIn
DrawGrid1.Canvas.StretchDr
finally
bmpTemp.Free; // free up temporary bitmap afterwards
end;
end;
To prevent stretching of the bitmaps just set the DefaultRowHeight and DefaultColumnWidth to the same dimensions of your bitmaps.
Hope this helps
Jo
Hello again...
To make that event handler a bit more generic you should change the formula for the index to read intIndex := (ACol * DrawGrid1.ColCount) + ARow;
Jo
To make that event handler a bit more generic you should change the formula for the index to read intIndex := (ACol * DrawGrid1.ColCount) + ARow;
Jo
You could try this:
procedure TForm1.DrawGrid1DrawCell(S ender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
Bmp : TBitmap;
begin
Bmp := TBitmap.Create;
Bmp.LoadFromFile('c:\mybit map' + IntToStr(((ARow + 1) * (ACol + 1))) + '.bmp');
DrawGrid1.Canvas.Draw(Rect .Left, Rect.Top, Bmp);
Bmp.Free;
end;
Cheers,
Alan
procedure TForm1.DrawGrid1DrawCell(S
Rect: TRect; State: TGridDrawState);
var
Bmp : TBitmap;
begin
Bmp := TBitmap.Create;
Bmp.LoadFromFile('c:\mybit
DrawGrid1.Canvas.Draw(Rect
Bmp.Free;
end;
Cheers,
Alan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER