Win a copy of The Business Blockchain this week in the Cloud forum!

# Bizarre touch coordinates

Jeet Dholakia
Greenhorn
Posts: 26
Im making an application for painting on a bitmap, and its been asked several times before on SO like here and here

I used them inside my app and none seemed to work , here's the code i have used:

Now, as i draw the path by touching on the screen, it just draws itself elsewhere, also it only happens in the images with have been scaled by android itself, not on images which are small enough to fit without scaling , please look into it and help me out

Thanks, Jeet

Steve Luke
Bartender
Posts: 4181
22
The coordinates you get from the event are screen coordinates. The coordinates you are painting on are image coordinates. Since the image is scaled, you should not expect those coordinates to be the same, so you can't just use the event's X and Y coordinates to paint with. Since the image is scaled, you will need to scale the coordinates the same way. That is usually done by getting the width and height of the original image and comparing them to the width and height of the image view to get a scaling factor. Then multiplying the coordinates appropriately.

Jeet Dholakia
Greenhorn
Posts: 26
Steve Luke wrote:The coordinates you get from the event are screen coordinates. The coordinates you are painting on are image coordinates. Since the image is scaled, you should not expect those coordinates to be the same, so you can't just use the event's X and Y coordinates to paint with. Since the image is scaled, you will need to scale the coordinates the same way. That is usually done by getting the width and height of the original image and comparing them to the width and height of the image view to get a scaling factor. Then multiplying the coordinates appropriately.

Thanks for pointing me in the correct direction,

i did some tinkering by myself, and I hope its useful to others

This are the steps i followed

1) Calculate original width and scaled width
2)find the scale ratio
3)multiply the scaled ratio to the events' x and y coordinate, and you can get the desired co-ordinates...