Android Change Color Of ImageView / Bitmap
I need to find a way to change the color of bitmap in Android. I need to replace/change colors of oval image smoothly in my application depending on int value. I need something lik
Solution 1:
This is how I solved this issue :
- Declare an ImageViewwithsrc="@drawable/button"
- Create a Drawableand setColorFilterto it and after that use it as src to your declaredImageViewlike this :
>
Drawable myIcon = getResources().getDrawable( R.drawable.button );
ColorFilter filter = new LightingColorFilter( Color.BLUE, Color.BLUE );
myIcon.setColorFilter(filter);
color.setImageDrawable(myIcon);
Solution 2:
This solution doesn't work very well for me. In some images the final color was wrong. I use this solution instead:
Drawable myIcon = getResources().getDrawable(R.drawable.your_image); 
myIcon.setColorFilter(Color.BLUE, PorterDuff.Mode.SRC_ATOP); 
((ImageView)findViewById(R.id.view_to_change)).setImageDrawable(myIcon);
Solution 3:
getResources().getDrawable( R.drawable.button );
is now deprecated. Can also do it this way:
((ImageView) findViewById(R.id.my_icon))
  .setColorFilter(new LightingColorFilter(Color.BLUE, Color.BLUE));
Solution 4:
Should you this.
Drawable myIcon = getResources().getDrawable( R.drawable.button ); 
ColorFilter filter = new LightingColorFilter( Color.BLACK, Color.BLACK);
myIcon.setColorFilter(filter);
Solution 5:
You can use a TransitionDrawable to achieve this - http://developer.android.com/reference/android/graphics/drawable/TransitionDrawable.html
Post a Comment for "Android Change Color Of ImageView / Bitmap"