1. Download our Official Android App: Forums for Android!

Repeated Images and Color Filters Applying to All

Discussion in 'Introductions' started by aibar, Nov 9, 2010.

  1. aibar

    aibar Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    2
    Joined:
    Nov 9, 2010

    Nov 9, 2010
    2
    0
    25
    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...
    Rank:
    None
    Points:
    843
    Posts:
    19,535
    Joined:
    Jul 9, 2010

    Jul 9, 2010
    19,535
    4,045
    843
    Male
    Engineer
    'neath a cactus
  3. aibar

    aibar Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    2
    Joined:
    Nov 9, 2010

    Nov 9, 2010
    2
    0
    25
    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...