15,559,491 members
3.00/5 (1 vote)
See more:
Hello, if I have a position (x, y) in an image, that is inside a picturebox,
how can I know the same position if i change the size of the image?
Thank you very much.re>

I will try to explain better what I need to do:
On an image (which is a plane) I want to mark a red dot where a fire detector goes.
That doing click with the mouse.
I take and store coordinates (x, y) so that each time that plane is shown (there are many) place each sensor in its place.
My problem is that if I change the size of the picturebox (sizemode = StretchImage) those coordinates are no longer valid. Thanks for answering so fast

What I have tried:

Get a position (x, y) that does not change if you change the size of an image.
Posted
Updated 11-Jul-18 23:17pm
v2
F-ES Sitecore 11-Jul-18 7:25am
Should just be basic maths. Work out the x coord as a percentage of the width. So if the image is 50 wide and x is 10, that is 20% (100/width * x). So if the image is changed to be 100 wide, 20% of 100 is 20 so that's your new x. If the image is shrunk to 25 then 20% of 25 is 5 so that's your new x. Do the same thing with y.
Sergio Bombien 13-Jul-18 3:46am
Thank you very much, I'm a little rusty with the math.

## Solution 1

Handle the resize event for the image control, and recalculate the desired coordinate(s) based on the change ratio for both sides of the image.

## Solution 2

Quote:
Hello, if I have a position (x, y) in an image, that is inside a picturebox,
how can I know the same position if i change the size of the image?

It is really simple maths.
First solution: get a real picture, spot a particular point measure its position in picture, make a copy with a change of size, and measure new position.
Compare old size and new size, old position and new position, find the maths.

Second solution: your problem and the maths are the same as:
you are a cashier and you earn 3 cents for every dollar you bill.
How much do you earn if you bill \$10, \$50, \$100 ...

Top Experts
Last 24hrsThis month
 OriginalGriff 95 Richard MacCutchan 25 Sandeep Mewara 25 CPallini 25 oliver sato (Paytvcard) 12
 OriginalGriff 4,149 Graeme_Grant 1,792 Richard MacCutchan 1,565 CPallini 942 Richard Deeming 805

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900