FMXTBitmapPixels (Delphi)
From RAD Studio Code Examples
Contents |
Description
This example shows how to use the TBitmap.Pixels property. This sample draws and fills the rectangle on an image, pixel by pixel.
To build and test this example, create a FireMonkey HD Application - Delphi, then add the next objects to the form:
- A TImage to display the initial TBitmap.
- A TImage to display the result.
- Two TLabels, one for each TImage.
- A TButton to draw on the initial image.
- A TOpenDialog and a TButton to load the image to be customized.
Add the following code to the OnClick event handlers of the load button.
Code
procedure TForm1.Button2Click(Sender: TObject); begin if OpenDialog1.Execute then begin Image1.Bitmap.LoadFromFile(OpenDialog1.FileName); end; end;
Add the following code to the OnClick event handlers of the other button.
Code
procedure TForm1.Button1Click(Sender: TObject); var MyBitmap: TBitmap; X, Y: Integer; begin MyBitmap := TBitmap.Create(0, 0); try if Image1.Bitmap.IsEmpty then // Display a message when there is no image loaded MessageDlg('There is no image to customize:', TMsgDlgType.mtWarning, [TMsgDlgBtn.mbOk], 0) else begin // A copy of the initial bitmap MyBitmap.Assign(Image1.Bitmap); // Changes the color of certain pixels for X := 20 to 200 do for Y := 10 to 100 do MyBitmap.Pixels[X, Y] := claLime; // Displaying the result Image2.Bitmap := MyBitmap; end; finally MyBitmap.Free; end; end;
The result should look like in the following image:
Uses
- FMX.Types.TBitmap.Pixels ( fr | de | ja )
- FMX.ObjectsTImage.Bitmap ( fr | de | ja )
See Also
- FMX.Objects.Objects.TImage ( fr | de | ja )
- FMX.Dialogs.TOpenDialog( fr | de | ja )
- C++ version of this example