I can not find an example to draw and move a rectangle over a bitmap.
I have to have an Image1 that contains the bitmap and an Image2 that contains the fixed rectangle, even when the bitmap changes in the Image1; in short, a kind of sumulation of layers
example:

- Code: Select all
void __fastcall TForm1::Button5Click(TObject *Sender)
{
Image1->Picture->LoadFromFile("mypicture.jpg");
bmp1= new Graphics::TBitmap;
bmp1->Assign(Form1->Image1->Picture->Graphic);
Image1->Picture->Bitmap->Assign(bmp1);
delete bmp1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
if(Shift.Contains(ssLeft))
{
Label7->Caption=X;
Label8->Caption=Y;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
Label4->Caption=X;
Label5->Caption=Y;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
int x1, y1, x2, y2;
x1=StrToInt(Label4->Caption);
y1=StrToInt(Label5->Caption);
x2=StrToInt(Label7->Caption);
y2=StrToInt(Label8->Caption);
Image2->Transparent=true;
Image2->Canvas->Pen->Color=clBlack;
Image2->Picture->Bitmap->Canvas->Rectangle(x1,y1,x2,y2);
}
//---------------------------------------------------------------------------