Repeated Images and Color Filters Applying to All


Last Updated:

  1. aibar

    aibar New Member This Topic's Starter

    Joined:
    Nov 9, 2010
    Messages:
    2
    Likes Received:
    0
    I'm using multiple ImageView elements in one of my GUI's and using the same image resource, repeated. I want to be able to apply a color filter to these ImageView's, but whenever I'm using the same image resource in multiple ImageView's and I apply a color filter to one of them, it applies it to all of them!

    I'm applying the filter like so:

    Code (Text):
    1. imgV.getDrawable().setColorFilter(null);
    2. imgV.getDrawable().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);
    Please help! I want to apply a color filter to just one of these ImageViews, even though they are using the same image resource.
     

    Advertisement
  2. Martimus

    Martimus One bite at a time... Moderator

    Joined:
    Jul 9, 2010
    Messages:
    19,535
    Likes Received:
    4,045
  3. aibar

    aibar New Member This Topic's Starter

    Joined:
    Nov 9, 2010
    Messages:
    2
    Likes Received:
    0
    So it turns out that after over a week of searching for this answer, it had little todo with my logic and everything to do with the framework.

    If you're using multiple ImageViews that may contain the same image resource using:

    Code (Text):
    1. imgV.getDrawable().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);
    will get the Drawable associated with that particular resource. Therefore, the filter will be applied anywhere that image resource is being referenced. To avoid this, use:

    Code (Text):
    1. imgV.setColorFilter(null);
    2. imgV.setColorFilter(0xFF8A2BE2, PorterDuff.Mode.MULTIPLY);
    [As a sidenote, setting the color filter to null is to remove any previous filters if you're applying multiple filters to the same ImageView programmatically]
     

Share This Page

Loading...