0

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 checking the color of that pixel (x,y) and as soon as it turns red , a touch event should be simulated.

Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83
Shubham Batra
  • 1,278
  • 1
  • 14
  • 27

1 Answers1

1

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;
        }
   });
Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83
  • 2
    note that ImageView width and height must be wrap_content. – hasan Dec 03 '14 at 13:00
  • @Murtaza I think you got me wrong there. I do not want to get color of pixel on onTouch, What I want is to keep a check on a particular pixel and when its color changes a touch event should be simulated. – Shubham Batra Dec 13 '14 at 17:38
  • well there is simple logic here. you can record the x and y position with r,g and b color codes, and compare with values on time interval, interval can be possible through many ways like AlarmManager and TimerTask – Murtaza Khursheed Hussain Dec 15 '14 at 07:29