FMXTBitmapClear (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to use the TBitmap clear functions and their results.

The TBitmap's clear functions are Clear and ClearRect.

To build and test this example, create a Multi-Device Application - Delphi, and add the following objects on the form:

Add a new bitmap as a global variable and name it MyBitmap. It will be used to save a copy of the initial bitmap.

Code

var
  Form1: TForm1;
  MyBitmap: TBitmap;

Add the following code to the OnCreate event handler of the form. The code loads the bitmap into Image1, so it can be manipulated, and initializes MyBitmap.

procedure TForm1.FormCreate(Sender: TObject);
begin
  //creates an empty bitmap
  MyBitmap:=TBitmap.Create(0,0);
  //loads the initial bitmap (to be manipulated) to Image1
  Image1.Bitmap.LoadFromFile('bitmap1.png');
end;

Add the following lines of code to the OnChange event handlers of each radio button. The result will be displayed on the Image2.

Code

procedure TForm1.RadioButton1Change(Sender: TObject);
begin
  //a copy of the initial bitmap
  MyBitmap.Assign(Image1.Bitmap);
  //clears the bitmap
  MyBitmap.Clear(clablue);
  //displays the result of the Clear function
  Image2.Bitmap:=MyBitmap;
end;

procedure TForm1.RadioButton2Change(Sender: TObject);
var
  MyRect: TRectF;
begin
  //the rectangle to be cleared
  MyRect.Create(50,30,80,100);
  //a copy of the initial bitmap
  MyBitmap.Assign(Image1.Bitmap);
  //clears the bitmap
  MyBitmap.ClearRect(MyRect);
  //displays the result of the ClearRect function
  Image2.Bitmap:=MyBitmap;

end;

The result should look like in the following images:

TBitmapClear1.png

TBitmapClear2.png

Uses

See Also