This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bizarre touch coordinates

 
Jeet Dholakia
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic