■ hex 함수를 사용해 RGBA 색상값을 ARGB 색상 16진수 문자열 값으로 구하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
red = 166 green = 128 blue = 255 alpha = 0.8 redHexadecimalString = hex(red ).replace("0x", "") greenHexadecimalString = hex(green).replace("0x", "") blueHexadecimalString = hex(blue ).replace("0x", "") alphaHexadecimalString = hex(int(round(alpha * 255, 0))).replace("0x", "") print(redHexadecimalString ) # a6 print(greenHexadecimalString) # 80 print(blueHexadecimalString ) # ff print(alphaHexadecimalString) # cc argbHexadecimalString = "#{alphaHexadecimalString}{redHexadecimalString}{greenHexadecimalString}{blueHexadecimalString}".format( alphaHexadecimalString = str(alphaHexadecimalString).ljust(2, "0"), redHexadecimalString = str(redHexadecimalString ).ljust(2, "0"), greenHexadecimalString = str(greenHexadecimalString).ljust(2, "0"), blueHexadecimalString = str(blueHexadecimalString ).ljust(2, "0") ) print(argbHexadecimalString) # #cca680ff |