There is a Scanline property on TBitmap.
Simple test:
procedure TForm1.FormPaint(Sender: TObject);
type
TPixelInfo = packed record
r, g, b: byte;
end;
var
b: TBitmap;
i, j: integer;
p: ^TPixelInfo;
begin
b:=TBitmap.Create;
b.PixelFormat:=pf24bit;
b.SetSize(ClientWidth, ClientHeight);
for j:=0 to ClientHeight-1 do begin
p:=b.ScanLine[j];
for i:=0 to ClientWidth-1 do begin
p[i].r:=i;
p[i].g:=j;
p[i].b:=255;
end;
end;
canvas.Draw(0, 0, b);
b.Free;
end;
It should make repeated 4 color gradient of red, magenta, yellow and white.
And no, it's not good practise to initialize TBitmap inside onPaint. I just tried how it works, and it's incredibly fast for me at least.
Also i know that i made the record wrong, it should've been b, g, r: byte, because bmp is awkward format...