Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply different colour filters on an image in android?

I can't figure out how can we apply filters over an image.

In this case I want the image to be darker (black, 40% transparency, layer on top of the image would give me the result I want). However, it will be helpful (in future) if I know how to put a layer over an image of any color (with some transparency) to make it more visually compatible with the other UI elements of the app.

How it looks

How it looks now.

enter image description here

How I want it to look on the app (the above image has been edited in Adobe illustrator but the app repeatedly crashes if I use it even though its size is not large)

Also, I suspect there must be a way to do this in android studio without the need of any image editing software.

Correct me if I am wrong ;)

like image 986
Raunaq Shah Avatar asked Feb 04 '26 07:02

Raunaq Shah


1 Answers

This is what i do ,

 imageView =(ImageView) findViewById(R.id.image_view) ;
 imageView.getDrawable().setColorFilter(0x76ffffff, PorterDuff.Mode.MULTIPLY );

color range [0x00000000 -0xffffffff]

If you don't understand the pattern this might help you

Red - 0xffff0000

green -0xff00ff00

blue - 0xff0000ff

your request average black color 0xff555555

change color codes as you want > here

out put

enter image description here enter image description here enter image description here enter image description here


Further more :

setColorFilter params : (int color, PorterDuff.Mode mode)

What does PorterDuff.Mode mean

like image 103
Charuක Avatar answered Feb 05 '26 20:02

Charuක



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!