Created
November 4, 2014 14:38
-
-
Save kanytu/2c80cff9b571f042b8f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imgUsrClrId.setOnTouchListener(new View.OnTouchListener() { | |
@Override | |
public boolean onTouch(View v, MotionEvent event) { | |
//***********************Get the position of the screen on image***************************// | |
float eventX = event.getX(); | |
float eventY = event.getY(); | |
float[] eventXY = new float[] {eventX, eventY}; | |
//***********************Get the position of the screen on image***************************// | |
//***********************Get the position of the image on image***************************// | |
Matrix invertMatrix = new Matrix(); | |
((ImageView)imgUsrClrId).getImageMatrix().invert(invertMatrix); | |
invertMatrix.mapPoints(eventXY); | |
int x = Integer.valueOf((int)eventXY[0]); | |
int y = Integer.valueOf((int)eventXY[1]); | |
//***********************Get the position of the image on image***************************// | |
//***********************Get the Size of the Drawable image***************************// | |
Drawable imgDrawable = ((ImageView)imgUsrClrId).getDrawable(); | |
Bitmap bitmap = ((BitmapDrawable)imgDrawable).getBitmap(); | |
//***********************Get the Size of the Drawable image***************************// | |
//***********************Get the Color code of the image*****************************// | |
//Limit x, y range within bitmap | |
if(x < 0){ | |
x = 0; | |
}else if(x > bitmap.getWidth()-1){ | |
x = bitmap.getWidth()-1; | |
} | |
if(y < 0){ | |
y = 0; | |
}else if(y > bitmap.getHeight()-1){ | |
y = bitmap.getHeight()-1; | |
} | |
//Get the hexadecimal value w.r.t x and y Co-ordinates | |
int touchedRGB = bitmap.getPixel(x, y); | |
txtColorCodeId.setText("#" + Integer.toHexString(touchedRGB)); | |
txtColorCodeId.setTextColor(touchedRGB); | |
//***********************Get the Color code of the image****************************// | |
return true; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment