Skip to content Skip to sidebar Skip to footer

Showing Color Selected From An Image On Touch Event In An Overlay

I want to display the color selected on touch of an image in an enlarged baloon just above the touch point . Similar to showing my current location in maps using itemized overlays.

Solution 1:

This is a very good question and the previous answer needed a bit more explanation by way of this code snippet:

    imageView1 = (ImageView)findViewById(R.id.imageView1);
    imageView1.setOnTouchListener(new View.OnTouchListener() { 
        public boolean onTouch(View v, MotionEvent event) { 
            if (event.getAction() == MotionEvent.ACTION_DOWN){
                int positionX = (int)event.getX();
                int positionY = (int)event.getY();              

                Log.i("ON TOUCH COORDINATES","x: "+positionX + " y: " + positionY);
                BitmapDrawable bd = (BitmapDrawable)imageView1.getDrawable(); 
                Bitmap bitmap = bd.getBitmap(); 
                int color_selected = bitmap.getPixel(positionX, positionY);
                Log.i("COLOR SELECTED"," "+color_selected);
            } 
            return true; 
        } 
    }); 

Post a Comment for "Showing Color Selected From An Image On Touch Event In An Overlay"