how to get color at the spot(or pixel) of a image on touch event in android

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.

  • Android: why setVisibility(View.GONE); or setVisibility(View.INVISIBLE); do not work
  • Cannot Write to sdcard in Android emulator
  • Android - Is Navigation Drawer from right hand side possible?
  • FacebookCallback.onCancel is getting called when trying to login using facebook sdk
  • html phonegap android : numeric soft keyboard has next instead of go button
  • How to do swipe gesture on RecyclerView item without 3rd party lib
  • Related posts:

    java.lang.NoClassDefFoundError while running JUnit test in Netbeans
    Bypassing Google TTS Engine initialization lag in Android
    Android webview after onJsAlert not responding taps
    How to clear cookies and cache of webview on Android when not in webview?
    Android Studio 1.0.2 new project - Cannot resolve symbol 'ActionBarActivity'
    How to configure an Android emulator for the Kindle Fire?
  • How to set text color to a text view programmatically
  • Android displaying text when ListView is empty
  • Can't launch the app in Android Studio 2.0 Preview
  • Open the last closed tab in Android Studio
  • Android: Error upload image in different android versions
  • How make a ListPreference with checkbox
  • 2 Solutions collect form web for “how to get color at the spot(or pixel) of a image on touch event in android”

    try this:

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

    You can compute the image coordinates of the pixel that was clicked and read the pixel from the image data, like

    Bitmap.getPixel(xcord,ycord)
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.