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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 IEBitmap.CopyRectTo in real-time

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
PeterPanino Posted - Dec 10 2022 : 14:09:34
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?

2   L A T E S T    R E P L I E S    (Newest First)
PeterPanino Posted - Dec 11 2022 : 02:55:26
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;
xequte Posted - Dec 10 2022 : 18:11:56
Hi

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



Nigel
Xequte Software
www.imageen.com