Created
July 2, 2020 08:05
-
-
Save nuintun/6131415298f30dcede37eabb5be23736 to your computer and use it in GitHub Desktop.
hex 和 rgb 颜色转换
This file contains hidden or 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
function rgb2hex(red, green, blue) { | |
const rgb = (red << 16) | (green << 8) | blue; | |
return `#${rgb.toString(16).padStart(6, '0')}`; | |
} | |
function hex2rgb(hex) { | |
return [(hex >> 16) & 0xff, (hex >> 8) & 0xff, hex & 0xff]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment