RGB to hex and hex to RGB

前端 未结 30 2838
遥遥无期
遥遥无期 2020-11-21 06:56

How to convert colors in RGB format to hex format and vice versa?

For example, convert \'#0080C0\' to (0, 128, 192).

30条回答
  •  梦如初夏
    2020-11-21 07:25

    R = HexToR("#FFFFFF");
    G = HexToG("#FFFFFF");
    B = HexToB("#FFFFFF");
    
    function HexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
    function HexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
    function HexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
    function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}
    

    Use these Function to achive the result without any issue. :)

提交回复
热议问题