FMXTBitmapStartLine (C++)
From RAD Studio XE2 Code Examples
Contents |
Description
This example shows how to use the TBitmap.StartLine property. This example rotates the RGB channel color of every pixel of an image.
To build and test this example, create a FireMonkey HD Application - C++, then add the next objects to the form:
- A TImage to display the initial TBitmap.
- A TImage to display the result.
- Two TLabel, 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
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 I; Byte T; PAlphaColorRecArray PixelRecs; 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); // Cast from 32-bit colors to color record PixelRecs = PAlphaColorRecArray(MyBitmap->StartLine); // Rotate RGB of every pixel for (I = 0; I < MyBitmap->Width * MyBitmap->Height - 1; I++) { T = (*PixelRecs)[I].R; // temp (*PixelRecs)[I].R = (*PixelRecs)[I].G; (*PixelRecs)[I].G = (*PixelRecs)[I].B; (*PixelRecs)[I].B = T; } // Display the result Image2->Bitmap = MyBitmap; } } __finally { delete MyBitmap; } }
The result should look like in the following image:
Uses
- FMX.Types.TBitmap.StartLine ( fr | de | ja )
- FMX.Types.PAlphaColorRecArray ( fr | de | ja )
- FMX.Objects.TImage.Bitmap ( fr | de | ja )
See Also
- FMX.Objects.Objects.TImage ( fr | de | ja )
- FMX.Dialogs.TOpenDialog( fr | de | ja )
- Delphi version of this example