Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
630 views
in Technique[技术] by (71.8m points)

colors - Programmatically darken a Hex colour


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you're not bothered about too much control, and just want a generally darker version of a colour, then:

col = (col & 0xfefefe) >> 1;

Is a nice quick way to halve a colour value (assuming it's packed as a byte per channel, obviously).

In the same way brighter would be:

col = (col & 0x7f7f7f) << 1;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...