Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I recognise which area of an image (not just coordinates) has been touched in Android?

I am currently developing an Android application for my final year project which should help autistic people indicate when something hurts and do so by touching a picture of the human body.

The problem I've encountered is I don't know how to identify the part of the image they touch. The image is a bitmap, held as a BitmapDrawable in an ImageView. First time is touched, it zooms in via an animation and setFilledAfter(true), and from there when an area is touched the app is supposed to recognize main parts of the body (e.g. head, left hand...).

The areas to be recognized aren't square so checking for coordinates is not really an option. I was thinking along the lines of having each part to be recognised as a different view drawn on top of the original picture, but I'm open too other solutions.

To make things a little bit more interesting the app should work on different devices and resolutions, in both mobiles and tablets.

Thank you so very much in advance for your help. It's really needed and appreciated.

EDIT

In the end what I will be trying is the following. I am going to have two copies of the image, one for display purposes, another internal, with the areas I want recognized painted in different colors. So the plan is to extrapolate the coordinates I obtain from the Touch event to find out to what pixel it corresponds to in regards to the original, the use Bitmap.getPixel() to determine waht color it is, then have a case statement returning the String of each part.

I am coding this right now, if anyone is interested leave a message and I will post how everything worked out, and I someone asks for it even the appropiate code :D

Thanks to Shade for giving me some other options to consider.

like image 951
Alex Avatar asked Mar 07 '11 09:03

Alex


1 Answers

Without having thought too much about this, it seems that your idea - to detect touches with overlay Views - seems to be good.

Apart from that, coordinates are also a good idea - you just have to define named areas of the image and check if the point of touch is within a certain area. Could be a bit more tedious, but may be better in terms of complexity when compared to having 20 views. It will also definitely be faster than adding 20 extra views in your application.

But above all, I think that you should experiment and see what is suitable to your concrete situation, because all else is guesswork.

EDIT:

If you do choose to use the polygon method, then you will have to deal with the problem of determining whether a point is inside of a polygon (see here for a short explanation).

Also, regarding Views, a View in Android is defined as a "rectangular area that occupies space on the screen". So that eliminates the possibility of non-rectangular Views. Perhaps there is the possibility of you defining a non-rectangular clickable area inside of a View, but I don't know if that is at all possible.

like image 90
Shade Avatar answered Oct 03 '22 03:10

Shade