ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 IEBitmap.CopyRectTo in real-time
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

981 Posts

Posted - Dec 10 2022 :  14:09:34  Show Profile  Reply
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?

xequte

39052 Posts

Posted - Dec 10 2022 :  18:11:56  Show Profile  Reply
Hi

If you interact with the TImageEnView.IEBitmap directly, you must call ImageEnView.Update();



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

981 Posts

Posted - Dec 11 2022 :  02:55:26  Show Profile  Reply
Hi Nigel,

Thanks for the quick hint on WE!

The clientPos does not reflect the cursor position relative to the image area but relative to the ImageEnView control boundaries:

// 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);


So how can I get the position relative to the image area?

UPDATE: I found the solution:

// Convert the screen coordinates of the mouse position to coordinates relative to the SourceImageEnView image area:
bitmapX := hyieutils.imin(hyieutils.imax(0, ImageEnViewSource.XScr2Bmp(X)), ImageEnViewSource.IEBitmap.Width - 1);
bitmapY := hyieutils.imin(hyieutils.imax(0, ImageEnViewSource.YScr2Bmp(Y)), ImageEnViewSource.IEBitmap.Height - 1);

// Define the rectangle to be copied from the ImageEnView's control:
rect.Left := bitmapX - 50;
rect.Top  := bitmapY - 50;
rect.Right := rect.Left + 100;
rect.Bottom := rect.Top + 100;
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: