I have one activity, my activity contains one ImageView.I have implemented OnTouchListener for ImageView.Here I want find pixels color where i touch in image.Please let me know how to find pixels color.I have one ideas,
–>In ImageView where i touch just find X and Y coordinate and find pixels in same X and Y coordinate and find pixels color.Please let me is it possible.
Please give any suggestion or document for to do this please.
with ur reference i wrote code for bitmap,
int mId=R.drawable.with_colors;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), mId);
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
In onTouch
int x=(int) event.getX();
int y=(int) event.getY();
int color=bitmap.getPixel(x, y);
Log.d("colors","---"+color);
But here Log printing “Colors—0”.
You can use the
getDrawable()method of the imageview to get what is drawn, and then get the bitmap from that by casting toBitmapDrawableand callinggetBitmap():To get the coordinates, assign an
OnTouchListener:In the code above you can basically just insert the first code where it says “get pixel at x, y” to get the pixel color.