FireMonkey TBitmap Pixels C++ Code Sample

By: Tim DelChiaro

Abstract: This example shows how to use the TBitmap.Pixels property. This sample draws and fills the rectangle on an image, pixel by pixel.

    FMXTBitmapPixels (C++)

 

    Language:

    Versions:

 

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 - C++, then add the next objects to the form:

Add the following code to the OnClick event handlers of the load button.

    Code

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

Add the following code to the OnClick event handlers of the other button.

    Code

void __fastcall TForm1::Button1Click(TObject *Sender) {
	TBitmap *MyBitmap = new TBitmap(0, 0);
	int X, Y;
	try {
		if (Image1->Bitmap->IsEmpty()) {
			// Display a message when there is no image loaded
			MessageDlg("There is no image to customize:",
				TMsgDlgType::mtWarning,
			TMsgDlgButtons() << TMsgDlgBtn::mbOK, 0);
		}
		else {
			// A copy of the initial bitmap
			MyBitmap->Assign(Image1->Bitmap);
			// Changes the color of certain pixels
			for (X = 20; X <= 200; X++) {
				for (Y = 10; Y <= 100; Y++) {
					MyBitmap->Pixels[X][Y] = claLime;
				}
			}
			// Display the result
			Image2->Bitmap = MyBitmap;
		}
	}
	__finally {
		delete MyBitmap;
 
	}
}

The result should look like in the following image:

File:TBitmap Pixel proprety.PNG

    Uses

    See Also

Server Response from: ETNASC04