I am trying develop something from my research work using android. But I am not a coding person, so I am having hard time figuring out how to do things. I figured out ways to acheive my functionality but I am kinda struck with a issue which I could not resolve on my own. It would be great if you guys could help me with it.
I am trying to display a image that is bigger than the screen size and make it to play a sound or vibrate when I touch a particular colored pixel within the image. I was able to perform this for the first instance of the image(i.e., the image displayed once I start my application), but as soon as I pan it doesn’t work. For example, my image has a green color pixel in the middle of the screen and after I pan it moved to the left. I am making it to vibrate once I touch the green pixel. The device vibrates when the green is i center, but after I pan it is not getting updated. It still vibrates when I touch the center of the screen even tough there is a different color. I am guessing that the program fixes the screen co-ordinates and are not using the image co-ordinates. I tried using event.getX, getRawX. But both are referencing to screen co-ordinate only.
My question is
*is there a way to target the image co-ordinate rather than screen co-ordinate?
*If not, how else can I accomplish this task?
Well, it’s kind of semantic, but there is no concept of “image co-ordinates”.
If you think about, the touch is handled in the first instance by a piece of hardware which has absolutely no knowledge of what your are touching except its’ physical pixels and this is what it reports to Android.
In turn, Android has no knowledge of what that chunk of image pixels is. The position of a particular image in your pixel relative to the screen only has meaning inside your app. Since the touch event originates outside your app, there is no way to associate the two….
….unless you make the association. So, you moved the image in your code in response to a touch event. Remember how far you moved it, using a variable defined in the class handling the touch event, and then use that as an offset to the x and y given to you in subsequent touch events.
E.g. You pan the image 200 pixels left. A dead centre touch now corresponds to the centre pixel of your image (x/2) + 200 since the physical pixel touched is now 200 to the right of the image centre.
[EDIT] Having thought a little more about this, you might be using a matrix to pan the image, and if you aren’t, then do check out the Matrix class. If you are, then you can query the matrix at any time to get the total amount of pan in x and y at any time. If you are also doing scaling and/or rotation, things get a bit more complex but that would merit a new question.
[EDIT]
To get the colour at your x,y: