FireMonkey Bitmap Manipulation C++ Sample Code

By: Tim DelChiaro

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

    FMXTBitmapManipulationFunctions (C++)

 

    Language:

    Versions:

 

Contents

    Description

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

The TBitmap manipulation functions are: FillColor,FlipHorizontalFlipVerticalInvertAlphaRotate.

To build and test this example, create a FireMonkey HD Application - C++, 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.

void __fastcall TForm1::Button1Click(TObject *Sender) {
	if (OpenDialog1->Execute()) {
		Image1->Bitmap->LoadFromFile(OpenDialog1->FileName);
	}
}

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

void __fastcall TForm1::Button2Click(TObject *Sender) {
	Image2->Bitmap->Assign(Image1->Bitmap);
	Image2->Bitmap->FillColor(ColorComboBox1->Color);
}

This is a result example for FillColor:

File:FMXTypesTBitmapFillColor.PNG

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

void __fastcall TForm1::Button3Click(TObject *Sender) {
	Image2->Bitmap->Assign(Image1->Bitmap);
	Image2->Bitmap->FlipHorizontal();
}

This is a result example for FlipHorizontal:

File:FMXTypesTBitmapFlipHorizontal.PNG

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

void __fastcall TForm1::Button4Click(TObject *Sender) {
	Image2->Bitmap->Assign(Image1->Bitmap);
	Image2->Bitmap->FlipVertical();
}

This is a result example for FlipVertical:

File:FMXTypesTBitmapFlipVertical.PNG

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

void __fastcall TForm1::Button6Click(TObject *Sender) {
	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();
}

This is a result example for InvertAlpha:

File:FMXTypesTBitmapInvertAlpha.PNG

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

void __fastcall TForm1::Button5Click(TObject *Sender) {
	Image2->Bitmap->Assign(Image1->Bitmap);
	Image2->Bitmap->Rotate(NumberBox1->Value);
}

This is a result example for Rotate:

File:FMXTypesTBitmapRotate.PNG

    Uses

    See Also

Server Response from: ETNASC02