14

我想获取我将在 Android 中触摸图像的点或像素的颜色。我在网上搜索了很多,但一无所获。请任何人帮助我。

4

2 回答 2

37

试试这个:

final Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
imageView.setOnTouchListener(new OnTouchListener(){
        @Override
        public boolean onTouch(View v, MotionEvent event){
        int x = (int)event.getX();
        int y = (int)event.getY();
        int pixel = bitmap.getPixel(x,y);

        //then do what you want with the pixel data, e.g
        int redValue = Color.red(pixel);
        int blueValue = Color.blue(pixel);
        int greenValue = Color.green(pixel);        
        return false;
        }
   });
于 2013-02-17T11:54:54.583 回答
3

您可以计算被点击的像素的图像坐标并从图像数据中读取像素,例如

Bitmap.getPixel(xcord,ycord)
于 2013-02-17T12:10:52.090 回答