Reputation: 2171
I am using custom RadioButton, where i need to make clickable only on the image visible area. As you can see in the image below , where I need to make clickable only on the image portion ie White and Green portion only, the black area will remain transparent and non clickable.
Thanks , Any help will really be appreciated.
Upvotes: 1
Views: 1102
Reputation: 45503
I think the easiest way to detect whether 'visible' content of the image was clicked, is to hook up an OnTouchListener, get the touch coordinates and subsequently get the color for those coordinates using Bitmap.getPixel(int x, int y)
. Since this will return an ARBG color, you should have little problems with images using an alpha channel. Anything that is 'transparent' (or black in this case) will be invalid, everything else will mean the actual content was tapped.
Upvotes: 1
Reputation: 19796
One simple way to do it would be to grab the the pixel color at the touch location. Then you can check if the pixel is transparent:
int color = Bitmap.getPixel(x,y); // x and y are the location of the touch event in Bitmap space
int alpha = Color.getAlpha(color);
boolean isTransparent = (alpha==0);
More details here.
Upvotes: 0