This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Android and the fly likes Bizarre touch coordinates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Mobile » Android
Bookmark "Bizarre touch coordinates" Watch "Bizarre touch coordinates" New topic
Author

Bizarre touch coordinates

Jeet Dholakia
Greenhorn

Joined: Dec 15, 2012
Posts: 25
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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.


Steve
Jeet Dholakia
Greenhorn

Joined: Dec 15, 2012
Posts: 25
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...

 
GeeCON Prague 2014
 
subject: Bizarre touch coordinates