FMXTBitmapManipulationFunctions (Delphi)

From RAD Studio XE2 Code Examples
Jump to: navigation, search

Language:

Versions:

Contents

Description

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

The TBitmap manipulation functions are: FillColor,FlipHorizontal, FlipVertical, InvertAlpha, Rotate.

To build and test this example, create a FireMonkey HD Application - Delphi, and add the following on the form:

Code

First of all, add the following code to the OnClick event handlers of the load button so you can open any bitmap you want.

procedure TForm1.Button1Click(Sender: TObject);
begin
   if OpenDialog1.Execute then
   begin
     Image1.Bitmap.LoadFromFile(OpenDialog1.FileName);
   end;
end;

Add the following codes to the OnClick event handler of the button for FillColor.

procedure TForm1.Button2Click(Sender: TObject);
begin
  Image2.Bitmap.Assign(Image1.Bitmap);
  Image2.Bitmap.FillColor(ColorComboBox1.Color);
end;

This is a result example for FillColor:

FMXTypesTBitmapFillColor.PNG

Add the following codes to the OnClick event handler of the button for FlipHorizontal.

procedure TForm1.Button3Click(Sender: TObject);
begin
  Image2.Bitmap.Assign(Image1.Bitmap);
  Image2.Bitmap.FlipHorizontal;
end;

This is a result example for FlipHorizontal:

FMXTypesTBitmapFlipHorizontal.PNG

Add the following codes to the OnClick event handler of the button for FlipVertical.

procedure TForm1.Button4Click(Sender: TObject);
begin
  Image2.Bitmap.Assign(Image1.Bitmap);
  Image2.Bitmap.FlipVertical;
end;

This is a result example for FlipVertical:

FMXTypesTBitmapFlipVertical.PNG

Add the following codes to the OnClick event handler of the button for InvertAlpha.

procedure TForm1.Button5Click(Sender: TObject);
begin
  Image2.Bitmap.Assign(Image1.Bitmap);
  //To see any changes, make sure that the image you are manipulating is already transparent
  //Otherwise, if the image is solid, the result of InvertAlpha is a completely transparent image 
  Image2.Bitmap.InvertAlpha;
end;

This is a result example for InvertAlpha:

FMXTypesTBitmapInvertAlpha.PNG

Add the following codes to the OnClick event handler of the button for Rotate.

procedure TForm1.Button6Click(Sender: TObject);
begin
  Image2.Bitmap.Assign(Image1.Bitmap);
  Image2.Bitmap.Rotate(NumberBox1.Value);
end;

This is a result example for Rotate:

FMXTypesTBitmapRotate.PNG

Uses

See Also

Personal tools
Previous Versions