Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically make a color more transparent

I'm working on a simple bar graph application that uses a static array of colors for divvying out bar colors. I would like the functionality to either draw bars normally, or slightly transparent.

Is there a way to programmatically adjust a color integer so that it's slightly transparent? Or will I have to statically define a transparent version of each color and then switch to using these versions whenever I want transparency?

like image 604
TrolliOlli Avatar asked Jun 21 '13 14:06

TrolliOlli


People also ask

Is there a color code for transparent?

You can actually apply a hex code color that is transparent. The hex code for transparent white (not that the color matters when it is fully transparent) is two zeros followed by white's hex code of FFFFFF or 00FFFFFF.

How do you set a transparent color?

On the Picture Format tab, select Color, and then select Set Transparent Color. Click the color in the picture or image that you want to make transparent. Note: You can't make more than one color in a picture transparent.

How do I make a color transparent in HTML?

#0000ffff - that is the code that you need for transparent. I just did it and it worked.


Video Answer


1 Answers

If you are using support library, you can use:

ColorUtils.setAlphaComponent(int color, int alpha); 

If you are not using support library, one-line solution taken from it's source code is:

int res = (color & 0x00ffffff) | (alpha << 24); 
like image 126
Anton Ryabyh Avatar answered Sep 28 '22 04:09

Anton Ryabyh