如何在此层次结构中获取ImageView的像素颜色?

时间:2014-07-30 08:14:19

标签: android imageview

我想获得中间ImageView的像素颜色。

怎么做?

这是Activity的onTouchEvent方法。

public boolean onTouchEvent(MotionEvent event) {
    int action = event.getAction();
    int x = (int)event.getX();
    int y = (int)event.getY();

    int pixel = bim_Map.getPixel(x, y);

    // How to get a pixel color of ImageView1?

    switch (action) {
        case MotionEvent.ACTION_UP :

            break;
    }
    return true;
}


以下是图表。

enter image description here

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:-1)

将新的OnTouchListener()应用于ImageView1,例如:

ImageView imgview1 = (ImageView) findViewById(id);
imgview1.setOnTouchListener(new OnTouchListener(){

                @Override
                public boolean onTouch(View v, MotionEvent event) {

                    int pixel = imgview1.getPixel(event.getX(), event.getY());
                    return true;
                }
});