Title: Get all the pixels of a specific colour from an image in an Imageview
Tags: java;android;imageview
Question: I am trying to get all the pixels of a specific colour from an image in an imageview. For example, in the image that I have attached, I need to get all the pixels that are Red in color into an array. Is it even possible to do something like that? if so, please point me in correct direction


Here is another answer: Try this
imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent ev) {
// TODO Auto-generated method stub
ImageView img = (ImageView) v;
final int evX = (int) ev.getX();
final int evY = (int) ev.getY();
img.setDrawingCacheEnabled(true);
Bitmap imgbmp = Bitmap.createBitmap(img.getDrawingCache());
img.setDrawingCacheEnabled(false);
try {
int pxl = imgbmp.getPixel(evX, evY);
pickedColorView.setBackgroundColor(pxl);
int redValue = Color.red(pxl);
int blueValue = Color.blue(pxl);
int greenValue = Color.green(pxl);
}catch (Exception ignore){
}
imgbmp.recycle();
return true;
}
});
Comment for this answer: This code can be used to get the color at a given pixel but what I need is to get all the pixels that are in a specific color.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:06/26/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<java><android><imageview>', 'Title': 'Get all the pixels of a specific colour from an image in an Imageview', 'ViewCount': 38, 'id': 51036647, 'user_AboutMe': '', 'user_AccountId': 9081872.0, 'user_DisplayName': 'shashank', 'user_Reputation': 33.0, 'user_Views': 17.0, 'user_id': 6761435.0}}