In most graphic programs like Photoshop and Gimp there is a colorize function so you can easily color a gray scale image with a color of your choice. I want to do the same thing with an image in my Android application. I have been looking into the setColorFilter function. This is what I tried.
ImageView border = (ImageView) findViewById(R.id.imageView);
int color = Color.parseColor("#F57F17"); // the color to use
border.setColorFilter(color, PorterDuff.Mode.OVERLAY);
This does exactly what I need. The only problem is that it also colors the transparent areas in the image. I want the transparent areas to stay transparent.
Is there any way to achieve this?
2
Answers
You are looking for SRC_ATOP:
Colorize the drawable then set it back.
I do this with binding and an adapter to override image colors of drawables.
Example, I change the drawable color based on selected status below:
Here is another example of overriding menu item colors when you need more dynamic control.
That should hopefully help you get what you are doing across the finish line.
Happy Coding.