Get Color(Pixel) information on onTouch (Android)

前端 未结 1 824
日久生厌
日久生厌 2021-01-27 14:04

Is there a way to get color of a pixel say (x,y) and check if its red and if it is red then send a touch event.

I want it to run in background and it should always be ch

相关标签:
1条回答
  • 2021-01-27 14:30

    You can get values from the following example.

    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);
    
    
                int red = Color.red(pixel);
                int blue = Color.blue(pixel);
                int green = Color.green(pixel);        
                return false;
            }
       });
    
    0 讨论(0)
提交回复
热议问题