FMX: Fill whole bitmap with a background color

  

I want to create a TImage component and fill the image with a background color. However my code is a bit longer than I have expected.

I have to set the width and height of bitmap.
I have to calculate the rectangle of the whole bitmap canvas.

If I remember correctly, in old Delphi versions, I can use FloodFill to fill the whole image with particular color. So I think I have definitively missed something.

Can someone figure out how to fill background color with simpler code?

Image := TImage.Create(nil);
Image.Position.X := 100;
Image.Position.Y := 100;
Image.Width := 500;
Image.Height := 500;
Image.Bitmap.Width := Trunc(Image.Width);
Image.Bitmap.Height := Trunc(Image.Height);
with Image.Bitmap.Canvas do
begin
BeginScene;
try
Fill.Color := TAlphaColors.Black;
FillRect(RectF(0, 0, Image.Bitmap.Width, Image.Bitmap.Height), 0, 0, [], 1.0);
finally
EndScene;
end;
end;

Comments are closed.