• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Bizarre touch coordinates

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...

 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic