Last active
March 11, 2017 15:44
-
-
Save act262/831829ed17fe2ff5e3e823a806e3bdd2 to your computer and use it in GitHub Desktop.
计算透明度百分比对应的十六进制值
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 计算透明度百分比对应的十六进制值 | |
*/ | |
println "透明度百分比 -> 16进制" | |
for (int percent = 100; percent >= 0; percent--) { | |
int alpha = Math.round(255 * percent / 100d); | |
// println String.format("% 2d%% -> %s ", percent, Integer.toHexString(alpha).toUpperCase()) | |
// 不带0x开头 | |
// println String.format("%d%% -> %02X", percent, alpha) | |
// 带0x开头 | |
println String.format("% 2d%% -> %#02X", percent, alpha) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment