Recent

Author Topic: Quesion about TATImageBox  (Read 3171 times)

stab

  • Full Member
  • ***
  • Posts: 234
Quesion about TATImageBox
« on: January 12, 2022, 06:30:36 pm »
Hi,

I'm trying learn how to use TATImageBox. Zooming and panning works great. Would like to be able to use MouseDown event, but my program doesn't enter my code even though I've assigned it.
Seem to me that the event is somehow disabled.

How could one enable it? %)

stab

  • Full Member
  • ***
  • Posts: 234
Re: Quesion about TATImageBox
« Reply #1 on: January 12, 2022, 11:38:40 pm »
following is excerpt from the lfm-code:
Code: Pascal  [Select][+][-]
  1.   if (bitmap2 = nil) or (not chkgColorRects.Checked[0]) then
  2.       object ATImageBox1: TATImageBox
  3.         Left = 392
  4.         Height = 415
  5.         Top = 0
  6.         Width = 432
  7.         HorzScrollBar.Tracking = True
  8.         VertScrollBar.Tracking = True
  9.         Align = alClient
  10.         AutoScroll = False
  11.         BorderStyle = bsNone
  12.         ClientHeight = 415
  13.         ClientWidth = 432
  14.         Color = clMedGray
  15.         ParentColor = False
  16.         PopupMenu = PopupMenu1
  17.         TabOrder = 0
  18.         OnClick = ATImageBox1Click
  19.         OnMouseDown = ATImageBox1MouseDown
  20.         OnMouseMove = ATImageBox1MouseMove
  21.         OptFitToWindow = True
  22.         OptDrag = False
  23.       end

and following corresponding code:

Code: Pascal  [Select][+][-]
  1. procedure TfrmExtractElevationCurves.ATImageBox1MouseDown(Sender: TObject;
  2.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  3. var
  4.   p : pBGRAPixel;
  5. begin
  6.   if (bitmap2 = nil) or (not chkgColorRects.Checked[0]) then Exit;
  7.  
  8.   p := bitmap2.ScanLine[y];
  9.   Inc(p, x);
  10.   AddColorRect(p^);
  11.   DrawColorRects;
  12. end;

Have put a breakpoint at:
  if (bitmap2 = nil) or (not chkgColorRects.Checked[0]) then
which is never hit

[Fixed code tags; please read How to use the Forum.]
« Last Edit: January 13, 2022, 12:24:07 am by trev »

jamie

  • Hero Member
  • *****
  • Posts: 4625
Re: Quesion about TATImageBox
« Reply #2 on: January 13, 2022, 03:06:47 am »
Look here..
https://github.com/Alexey-T/ATViewer/blob/master/Source/ATImageBox.pas

Study the source code.


The image is overlaying the ImageBox, there for your mouse messages are being sent to the image instead.

Maybe you can make some alterations of the source code to fix your needs if you really need to use that.

 Me, I would simply piece some code together so I could get better control over it.

 TScrollBox and Timage most likely will do as you need.
The only true wisdom is knowing you know nothing

stab

  • Full Member
  • ***
  • Posts: 234
Re: Quesion about TATImageBox
« Reply #3 on: January 13, 2022, 02:05:06 pm »
Thanks alot, should have thought about that myself. Have to figure out, how to mediate the message. :)

AlexTP

  • Hero Member
  • *****
  • Posts: 1814
    • UVviewsoft
Re: Quesion about TATImageBox
« Reply #4 on: January 13, 2022, 02:49:09 pm »

stab

  • Full Member
  • ***
  • Posts: 234
Re: Quesion about TATImageBox
« Reply #5 on: January 13, 2022, 08:44:58 pm »
Thanks a lot Alextp,

Now it works even though I don't quite understand your changes.
What I want to do is to be able to pick pixels from the image, but feel a little unsure where in the image I'm pointing when zoomed in.
Could you please explain that to me? %)

AlexTP

  • Hero Member
  • *****
  • Posts: 1814
    • UVviewsoft
Re: Quesion about TATImageBox
« Reply #6 on: January 13, 2022, 10:11:40 pm »
That may be a useful feature-- some event or prop, so you can detect image pixel under the mouse. Will see it.

AlexTP

  • Hero Member
  • *****
  • Posts: 1814
    • UVviewsoft
Re: Quesion about TATImageBox
« Reply #7 on: January 13, 2022, 10:17:02 pm »
Try to do this: (I didn't test yet)

- ATImageBox has the public prop Image: TImage
- in the MouseMove event, get X/Y params, and do conversion from screen coords, to Image related coords. Like

  P:= ATImageBox1.ClientToScreen(Point(X, Y));
  P:= ATImageBox1.Image.ScreenToClient(P);

now you have P. Image related coords. Read the zooming value (prop ImageZoom, in percents) and scale P.

stab

  • Full Member
  • ***
  • Posts: 234
Re: Quesion about TATImageBox
« Reply #8 on: January 13, 2022, 11:50:46 pm »
Tried this:
Code: Pascal  [Select][+][-]
  1. procedure TfrmExtractElevationCurves.ATImageBox1MouseMove(Sender: TObject;
  2.   Shift: TShiftState; X, Y: Integer);
  3. var
  4.   Button: TMouseButton;
  5.   P : TPoint;
  6.   xs, ys, z : single;
  7. begin
  8.   P := ATImageBox1.ClientToScreen(Point(X, Y));
  9.   P:= ATImageBox1.Image.ScreenToClient(P);
  10.   xs := P.X; ys := P.Y;
  11.   z := 0.01 * ATImageBox1.ImageZoom;
  12.   P.X := Round(xs / z);
  13.   P.Y := Round(ys / z);
  14.   StatusBar1.SimpleText := 'X: ' + IntToStr(x) + ' Y: ' + IntToStr(y) + ' ' +
  15.     'Zoom: ' + IntToStr(ATImageBox1.ImageZoom) + ' - ' +
  16.     'X: ' + IntToStr(P.X) + ' Y: ' + IntToStr(P.Y);
  17. end;
  18.  
  19.  

But I didn't get it to work. It seems to be connected to drag coordinates in some way.  %)

AlexTP

  • Hero Member
  • *****
  • Posts: 1814
    • UVviewsoft
Re: Quesion about TATImageBox
« Reply #9 on: January 14, 2022, 12:30:14 am »
I fixed this, now X/Y must be right, I tested it on a small demo with resized picture. Updated in GH.

stab

  • Full Member
  • ***
  • Posts: 234
Re: Quesion about TATImageBox
« Reply #10 on: January 14, 2022, 03:47:50 pm »
Thanks again, now it's working nicely and keeping coordinates when panning and zooming.

Just wonder if you might have forgotten to update the zip-file in GH. I first downloded the zip-file and installed new package but was then back in original functionality.
Then I copied the pas-file and after that all worked.

/stab :D

AlexTP

  • Hero Member
  • *****
  • Posts: 1814
    • UVviewsoft
Re: Quesion about TATImageBox
« Reply #11 on: January 14, 2022, 04:02:25 pm »
Zip files are called 'releases',I will update it soon.

 

TinyPortal © 2005-2018