0

Customize image bounding box

I'm creating an Android app and it uses a cookie(circular) image in the UI. I have to detect clicks on the cookie only. However, as images are rectangular, the large transparent area around the cookie is also a part of the image, even though it's not visible. The issue of this is that if I click anywhere near the cookie, that will still be detected as a click on the image. So how can I make sure that doesn't happen, and only clicks on the cookie are detected?

23rd Jun 2025, 5:31 PM
Afnan Irtesum Chowdhury
Afnan Irtesum Chowdhury - avatar
1 Respuesta
+ 1
Get the pixel color at the click position and check the alpha value to determine if the click was on the cookie or the surround. Or if the cookie is round, use the distance of the click location to the center.
23rd Jun 2025, 5:44 PM
Lisa
Lisa - avatar