如何让在专色一个图像(或像素)对Android的触摸事件像素、图像、事件、Android

2023-09-03 23:27:21 作者:隱姓埋名

我想获得点或像素,我会触摸图像中的Andr​​oid的颜色。我搜索了很多关于网,但一无所获。请人帮我。

I want to get the color of the spot or pixel where I will touch a image in Android. I searched a lot on net, but got nothing. Please anyone help me.

推荐答案

试试这个:

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;
        }
   });