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
You could tag the ImageView
(or any View for that matter) with the data you're interested in retrieving later on. For example, tag the view with the same Color
that you use to construct the PorterDuffColorFilter
:
Color tagColor = Color.rgb(Color.red(color),Color.green(color), Color.blue(color));
// tag
imageview.setTag(tagColor);
// get tag
tagColor = (Color) imageview.getTag();
Obviously the tag will get garbage collected when the related view does.
Alternatively, the approach in your 3rd code snippet might actually work if you fix it up. Currently you're trying to inflate a view by looking for a drawable id - that doesn't make sense. The id should be in the form of R.id.imageview_id
, i.e.:
ImageView image = (ImageView) findViewById(R.id.imageview);
ColorFilter test = image.getColorFilter();