我已将 PNG 图像(具有透明背景的图像)设置为按钮背景,当我触摸按钮时,它会显示按钮触摸位置的 X 坐标和 Y 坐标,但是,我想知道按钮触摸位置的像素颜色按钮。
其实我想知道触摸的位置是按钮的透明区域还是按钮的彩色区域。您可以检查我为此目的开发的代码。请在这方面帮助我;我们将衷心感谢您的帮助。
button.setOnTouchListener(new OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
int x_coordinate = (int)event.getX();
int y_coordinate = (int)event.getY();
//int color = Bitmap.getPixel(x,y);
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
}
if (event.getAction() == MotionEvent.ACTION_UP)
{
}
return true;
}
});
Try this
Drawable drawable = button.getBackground();
Bitmap bmp = ((BitmapDrawable) drawable).getBitmap();
int color = bmp.getPixel(x_coordinate, y_coordinate);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)