I'm trying to get the color of an ImageView within a GridView that I've applied a color filter too previously. I'm running on a Nexus 4 with 4.2.2
I'm altering the color of the ImageView like this. The actual color of the image is white before I apply a filter.
Drawable myIcon = getResources().getDrawable(R.drawable.bufferbuildercolor3);
myIcon.setColorFilter(new PorterDuffColorFilter(Color.rgb(Color.red(color),Color.green(color), Color.blue(color)),PorterDuff.Mode.MULTIPLY));
Now this doesn't actually alter the source images color which is what I want. That always remains white.
My problem is I'm trying to reference the color well after I've lost the data I used to set it. I want to long press on the ImageView and get its color.
I found some code at the below question, but it doesn't appear to work as it always returns white (255,255,255), which IS the color of the original image, but not the filter. How to Get Pixel Colour in Android?
ImageView imageView = ((ImageView)v);
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
int pixel = bitmap.getPixel(x,y);
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);
I've tried stuff like the below, but it just crashes when I call getColorFilter.
ImageView image = (ImageView)findViewById(R.drawable.bufferbuildercolor3);
ColorFilter test = image.getColorFilter();
I'm not sure what else to do, except maybe find the X/Y of the actual grid position, and then get the screens background color at that point rather than the images. It seems like there should be an easier way to do this though?