简体   繁体   中英

PNG transparency and touches in android

I have a png, when I save it it is a square image, but inside the square png is a circle (sometimes its other shapes). How can I check when the user is over what is inside the png and a graphic rather than when a user is inside a png but is over transparency?

Yea, you can do this, you just need to manually check the color of the pixel where the touch occurred.

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);

Note: Depending on how you implement your touch listener will might need to convert the x,y location of the touch event to the x,y coordinates of the image view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM