Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

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...

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic