Android - Get Color From ImageView with ColorFIlter Applied to Drawable

前端 未结 1 1613
长情又很酷
长情又很酷 2021-01-18 07:13

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

相关标签:
1条回答
  • 2021-01-18 07:46

    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();
    
    0 讨论(0)
提交回复
热议问题