Hello Onur2x,
There are various possible problems:
- the rectangles are bigger than necessary
- the font rendering is in itself too slow
- the text outside the visible area is drawn needlessly
For the first problem, you can fix the size of the rectangles by writing the code in a simpler way.
For the second, you can use a lighter text rendering by setting the FontQuality property.
For the third, you can check if the area is actually visible.
Drawing text is generally a slow process though. If all of these are not enough, I suggest to store in a cache the rendered cells. At a next rendering phase, you can reuse the cache those that are still visible and free the unused cache.
procedure Tform1.button1click(Sender: Tobject);
const
roww = 30;
colw = 80;
var
a: TBGRABitmap;
r, c, x, y: integer;
cellRect: TRect;
Begin
a:=TBGRABitmap.Create;
a.SetSize(self.ClientWidth, self.ClientHeight); // use client size
a.Fill(CSSRed); // use BGRA constants
a.FontQuality:= fqSystemClearType; // less precision but faster
y:=0;
for r:=0 to 250 do
begin
x:=0;
for c:=0 to 5 do
begin
cellRect := RectWithSize(x, y, colw, roww); // specify size
// check if cell actually visible
if cellRect.IntersectsWith(ClientRect) then
a.TextRect(cellRect, r.ToString, taCenter, tlCenter, BGRABlack);
x += colw;
end;
y += roww;
End;
... // do something with the bitmap
a.free; // free memory
End;