Reputation: 4731
I have an ImageView
in my layout. I set a color to that Image using setColorFilter()
. Now I am trying to get the same color using getColorFilter()
. But its returning a ColorFilter
object. How can I extract hex color from it.
This is the way I am trying to set color to the Image:
image.setColorFilter(Color.parseColor("#ECECEC"), PorterDuff.Mode.MULTIPLY);
Now I am using below code which is returning a ColorFilter
object:
image.getColorFilter()
But how to get hex value or RGB value of the color from it ?
Upvotes: 1
Views: 1528
Reputation: 12379
It seems the method to get the color is hidden for reasons best known to google:
/**
* Returns the ARGB color used to tint the source pixels when this filter
* is applied.
*
* @see Color
* @see #setColor(int)
*
* @hide
*/
public int getColor() {
return mColor;
}
You can use a variable to store that:
int colorFilterColor ;
and While setting colorFilter:
int color = Color.parseColor("#ECECEC");
image.setColorFilter(color , PorterDuff.Mode.MULTIPLY);
colorFilterColor = color ;
For getting color:
public int getFilterColor(){
return colorFilterColor ;
}
Upvotes: 4