View Full Version : Incorrect coordinates for drawing rectanlge

August 28, 2013, 18:55:47
Hi, please take a look at the drawing rectangle code I have written. The LabVIEW code is attached in the next post.

It does draw a rectangle, but where I click and where the rectangle is drawn are two very different points.

I am getting X0 and Y0 from the MouseDown event. I get X1 and Y1 from the MouseUp event. (so the user "drags" a rectangle onto the control)

Why are the coordinates so off? I spoke with a colleague and she suggested that the coordinates are different-- e.g. control coordinates and screen coordinates but this doesn't make sense. The docs suggest those are one and the same. is there some kind of conversion I must do?

August 28, 2013, 21:36:50
See the reduced test-case VI, or as reduced as I can make it. The main VI is simply called MAIN.vi. It's in LabVIEW 2011--let me know if you need an earlier version.


Stefan Geissler
August 29, 2013, 08:54:24
Hello Paul

the coordinates for drawing a related to the video image. As far as I know the mouse coordinates are the application Window's coordinates (not screen).

August 29, 2013, 17:37:38
I don't think that's right. The Mouse coordinates definitely reference the top-left of the control--clicking in that area gives me 0,0. The other corners give expected results. I think DrawSolidRect is doing something incorrect, because it claims to reference the same coordinate system.

August 29, 2013, 17:57:18
The attached image should make clear my meaning. It looks like the coordinates are being 'halved' (or doubled ) even though the two have the same origin. Why? I multiply mouse click coordinates by 2 and it's ok but I'm wondering if this is a trick of the resolution of the monitor vs. control that's making this happen...

Click this one: 1622

August 29, 2013, 18:10:28
update: The factor of "2" only seems to work if I don't modify LiveDisplayWidth and LiveDisplayHeight. If I change those, the scaling factor is different. Window size is irrelevant, only control size.

So I really need to know what DrawSolidRect expects. It would be really nice if it just accepted numbers in terms of mouse coordinates.

Stefan Geissler
August 30, 2013, 10:35:26
The mouse coordinates are not affected by changing LiveDisplayWidth and LiveDisplayHeight. They are always the pixel position of the controll window. If you change LiveDisplayWidth and LiveDisplayHeight, you must calculate the mouse coordinates to the resized video size. If you want to change LiveDisplayTop and -Left, you must calcualte the mouse coordinates accordingly to match to the position on the live video image.

The OverlayBitmap drawing functions draw directly on the video bitmaps. Therefore, the LiveDisplay* functions do not affect them. Also, if you draw a line and show the live video smaller than original, then the line can disappear, because it is simply to small to be displayed resized.