Hola NEG1414.
Usando un arreglo podes hacer:
Código:
...
void copiar(TRect R)
{
for(int x = R.left; x<R.right; x++)
for(int y= R.top; y<R.Bottom; y++)
Fondo[x][y] = Form1->Canvas->Pixels[x][y];
}
void pegar(TRect R, int PX, int PY)
{
for(int x = R.left; x<R.right; x++)
for(int y= R.top; y<R.Bottom; y++)
Form1->Canvas->Pixels[PX+x][PY+y] = Fondo[x][y];
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Canvas->TextOutA(0,0,"PRUEBA");
// salvar el área de 'PRUEBA'
copiar(Rect(0, 0, Canvas->TextWidth("PRUEBA"),
Canvas->TextHeight("PRUEBA")));
// escribir algo sobre 'PRUEBA'
Canvas->TextOutA(0 0, "XX");
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// restaurar el área
pegar(Rect(0,0,Canvas->TextWidth("PRUEBA"),
Canvas->TextHeight("PRUEBA")), 0, 0);
}
Pero si queres ahorrarte el arreglo bidimensional, podrías guardar el área como un
TBitmap, por ejemplo:
Header:
Código:
class TForm1 : public TForm
{
__published:
TImage *Image1;
TLabel *Label1; // sobre la imágen
TButton *Button1;
TButton *Button2;
...
void __fastcall Button1Click(TObject *Sender);
private:
Graphics::TBitmap *FBM;
void __fastcall GetWndArea(int x1, int y1, int x2, int y2);
...
Código:
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
FBM = new Graphics::TBitmap;
randomize();
}
void __fastcall TForm1::GetWndArea(int x1, int y1, int x2, int y2)
{
FBM->Width = x2-x1;
FBM->Height= y2-y1;
TRect R = Rect(0,0,FBM->Width,FBM->Height);
FBM->Canvas->CopyRect(R, Canvas, R);
}
void Modificar(Graphics::TBitmap *B)
{
int x,y;
for(y=0; y < B->Height; y++) {
for(x=0; x < B->Width; x++)
B->Canvas->Pixels[x][y] = (TColor)(rand()% 0xFFFFFFF);
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// salvar el área de la imagen
GetWndArea(0, 0, Image1->Width,Image1->Height);
// modificarla
Modificar(Image1->Picture->Bitmap);
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// restaurar el área
Canvas->Draw(0, 0, FBM);
}
Saludos