我已经设置了一个PNG图像(具有透明背景的图像)作为按钮背景,当我触摸按钮时,它会显示按钮的触摸位置的X坐标和Y坐标,但是我想知道所触摸位置的像素颜色的按钮。如何获取Android中的像素颜色?
其实我想知道触摸的位置是按钮的透明区域还是按钮的着色区域。你可以检查我为此开发的代码。在这方面请帮助我;您的帮助将受到热烈的赞赏。
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;
}
});
我的应用程序保持FC,因为我的图像比我的背景小。你能帮忙吗? – Si8 2014-01-28 01:19:09
我不知道你的意思是FC。但是,如果您调整图像大小,则可以启用图形缓存,然后调用[getDrawingCache](http://developer.android.com/reference/android/view/View.html#getDrawingCache()),然后在该位图上工作。 – MalaKa 2014-01-28 09:49:57
这里是链接:http://stackoverflow.com/questions/21420278/how-to-keep-an-image-inside-layout-on-drag – Si8 2014-01-29 02:08:07