开发者

Android, check alpha of pixel?

开发者 https://www.devze.com 2023-04-10 18:00 出处:网络
I get the colour of my bitmap under th开发者_如何学编程e touch x and y: int myX = (int)event.getX();

I get the colour of my bitmap under th开发者_如何学编程e touch x and y:

int myX = (int)event.getX();
int myY = (int)event.getY();
int color = pngTestBM.getPixel(myX,myY);

How can I check if the pixel is transparent?


What about alpha method of Color class?

int transparency = Color.alpha(color);


The color is a 32 bit ARGB value, and a completely opaque pixel has an Alpha value of 0xff whilst a completely transparent pixel has an alpha value of 0x00.

Assuming you just want to find out if it is completely transparent you can just do:

int color = pngTestBM.getPixel(myX, myY);
boolean transparent = (color & 0xff000000) == 0x0;


Here you are:

int alpha = Color.alpha(pixel);
0

精彩评论

暂无评论...
验证码 换一张
取 消