RAD Studio
ContentsIndex
PreviousUpNext
Setting the Brush Bitmap Property

A brush's Bitmap property lets you specify a bitmap image for the brush to use as a pattern for filling shapes and other areas. 

The following example loads a bitmap from a file and assigns it to the Brush of the Canvas of Form1:

var
Bitmap: TBitmap;
begin
Bitmap := TBitmap.Create;
try
Bitmap.LoadFromFile('MyBitmap.bmp');
Form1.Canvas.Brush.Bitmap := Bitmap;
Form1.Canvas.FillRect(Rect(0,0,100,100));
finally
Form1.Canvas.Brush.Bitmap := nil;
Bitmap.Free;
end;
end;

 

BrushBmp->LoadFromFile("MyBitmap.bmp");
Form1->Canvas->Brush->Bitmap = BrushBmp;
Form1->Canvas->FillRect(Rect(0,0,100,100));

Note: The brush does not assume ownership of a bitmap object assigned to its Bitmap property. You must ensure that the Bitmap object remains valid for the lifetime of the Brush, and you must free the Bitmap object yourself afterwards.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!