Android Question click events using irregular shapes

clydebamford

Member
Licensed User
Longtime User
Im writting an app to offer feedback as to where on the screen a person has touched,
That is i have a face on the screen and i want to call different responses depending on what part of the face has been touched.
Thought of using many buttons arranged in zones to represnt " hair" or "face or "eyes"
then i thought of just reading the touched coordinates and applying a series of if statements but it would be very clumsy
then i saw a post about using jpegs with transparent backgrounds, will it not generate a touch event when touched on the transparent area? I guess i'll have to play around with it
Any other ideas?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Don't use buttons.

I think that you didn't understand the "transparent solution".
You can put the image on a panel and then find the touched pixel color. If the original image is made of a few colors then you can now know which part of the image was touched.

If the image is not made of several discrete colors then you can put another image about this one. The new image will be made of almost transparent colors with slightly different values. From these values you can find the touched shape.
 
Upvote 0

clydebamford

Member
Licensed User
Longtime User
thanks erel, i get it now and think i can make it work, but will have a look at steves hotspot too
ended up loading an identical image that id photoshoped with zones of single colors as a bmp variable and using the touch coordinates to lookup the colors on the bmp, works like a charm. was quite difficult to get rid of the few pixels that werent exactly the right color and have to watch the format as they changed color wen i saved/converted the file, murphies law again!
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
I was thinking of exclusion.. that's if the background color is white (the form color) then you can
make the corner colors (or any part not related to the picture) also white. Then look for the
(not-white)... if the pix is not white the event is executed.
 
Upvote 0
Top