Description
This example shows how to use the TBitmap.ScantLine property. This example copies the initial image to the middle of another image.
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(Image1->Bitmap->Width * 2,
Image1->Bitmap->Height * 2);
int I, J, baseX, baseY;
PAlphaColorArray SourceLine, TargetLine;
// Create MyBitmap twice the size of initial bitmap
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 {
MyBitmap->Clear(claBlue);
// From one quarter to the right, starting three quarters down
baseX = MyBitmap->Width / 4;
baseY = MyBitmap->Height * 3 / 4;
// Copy the image to the middle of MyBitmap from bottom up
for (I = 0; I <= Image1->Bitmap->Height - 1; I++) {
SourceLine = Image1->Bitmap->ScanLine[I];
TargetLine = MyBitmap->ScanLine[baseY - I];
// Copy the content of the pointer to another pointer
for (J = 0; J < (Image1->Bitmap->Width - 1); J++) {
(*TargetLine)[baseX + J] = (*SourceLine)[J];
}
}
// Display the result
Image2->Bitmap = MyBitmap;
}
}
__finally {
delete MyBitmap;
}
}
The result should look like in the following image:

Uses
See Also