Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
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 22:17pm
v2
Comments
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.

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.
 
Share this answer
 
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 ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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