I need to copy the 100 x 100 pixel rectangle around the mouse cursor from a Source ImageEnView in real-time to a zoomed Target ImageEnView while moving the mouse pointer over the Source ImageEnView. So I wrote this code:
procedure TformMain.ImageEnViewSourceMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
mousePos, clientPos: TPoint;
rect: TRect;
begin
// Get the position of the mouse cursor in screen coordinates:
GetCursorPos(mousePos);
// Convert the screen coordinates of the mouse cursor to client coordinates
// relative to the top-left corner of the Source ImageEnView:
clientPos := ImageEnViewSource.ScreenToClient(mousePos);
// Define the rectangle to be copied from the Source ImageEnView's control:
rect.Left := clientPos.X - 50;
rect.Top := clientPos.Y - 50;
rect.Right := rect.Left + 100;
rect.Bottom := rect.Top + 100;
// Copy the 100 x 100 area from the Source ImageEnView's control to the Target ImageEnView:
ImageEnViewSource.IEBitmap.CopyRectTo(
ImageEnViewPreviewMouseCursor.IEBitmap, // source control
rect.Left, // source rectangle left
rect.Top, // source rectangle top
0, // destination rectangle left
0, // destination rectangle top
rect.Width, // rectangle width
rect.Height // rectangle height
);
//ImageEnViewPreviewMouseCursor.Zoom := 200; // TImageEnView.Zoom is not published!
CodeSite.Send('TformMain.ImageEnViewSourceMouseMove: ');
end;
Unfortunately, only the first time the procedure is executed the rectangle gets copied!
So how can the rectangle be copied in real-time while moving the mouse?