RGB and hexadecimal conversion

1. RGB hexadecimal change

例:  var color = '#69ad52'

let r = parseInt(“0px” + color.slice(1, 3))  //105

let g = parseInt(“0px” + color.slice(3, 5)) //173

let b = parseInt(“0px” + color.slice(5, 7)) //82

 

2.RGB turn hex

例:  var color = 'rgb(105, 173,82)'

let hex = "#" + (( 1<< 24 ) + ( r << 16 ) + ( g << 8 ) + b).toString(16).slice(1)  // #69ad52

Guess you like

Origin www.cnblogs.com/reround/p/12068822.html