Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello guys, does anyone have any function to convert RGB Colors to HEX?
example:
255,0,0
to
# FF0000
Solved! Go to Solution.
Hello guys, does anyone have any function to convert RGB Colors to HEX?
example:
255,0,0
to
# FF0000
Solved! Go to Solution.
Hi,
You can start from this:
(defun int2hex (i / s a)
(setq s "")
(cond
((= i 0) "0")
(T
(while (> i 0)
(setq a (rem i 16)
i (lsh i -4)
s (strcat
(if (< a 10)
(chr (+ 48 a))
(chr (+ 55 a))
)
s
)
)
)
)
)
)
(defun padLeft (s i x)
(while (< (strlen s) i)
(setq s (strcat x s))
)
s
)
(defun rgb2hex (r g b)
(strcat
(padLeft (int2hex r) 2 "0")
(padLeft (int2hex g) 2 "0")
(padLeft (int2hex b) 2 "0")
)
)
(rgb2hex 255 0 0) => "FF0000"