mco_dolo
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2018
05:52 PM
How to convert rgba to hex?
I have a color in rgba format coming from the server, but I don't think roku can understand rgba, so was wondering if there was a convenient api to convert rgba to hex?
Example:
(255, 255 , 255, 255) - > 0xFFFFFFFF
Thanks
Example:
(255, 255 , 255, 255) - > 0xFFFFFFFF
Thanks
4 REPLIES 4

Komag
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2018
10:23 AM
Re: How to convert rgba to hex?
Dunno if there is one, but should be pretty easy to code one up I would think.
mco_dolo
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2018
01:02 PM
Re: How to convert rgba to hex?
Yea, I just wrote a function for it
// Example: If you input 255, 255, 255, 255 as the argument it will return "0xFFFFFFFF"
function rgbaToHex(r as integer, g as integer, b as integer, a as integer)
hexArray = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
hexColor = "0x"
for i = 0 to 3
colorChannel = invalid
if(i = 0) then
colorChannel = r
else if(i = 1) then
colorChannel = g
else if(i=2) then
colorChannel = b
else if(i=3) then
colorChannel = a
end if
sixteens = int(colorChannel / 16) // How many 16's can go into colorChannel (since hex is base 16)?
ones = colorChannel mod 16 // How many 1's are in the remainder?
hexColor += hexArray[sixteens] + hexArray[ones]
end for
return hexColor
end function
rftvaa
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2018
07:35 AM
Re: How to convert rgba to hex?
Hi,
you can improve your solution by using StrI(value as Integer, radix as Integer) as String
example: StrI(255, 16) '= "ff"
you can improve your solution by using StrI(value as Integer, radix as Integer) as String
example: StrI(255, 16) '= "ff"
necrotek
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2018
03:50 PM
Re: How to convert rgba to hex?
You can use a bitshift
function rgbToColor(r, g, b, a,LE=false)
if LE=true'(LITTLE_ENDIAN)
return ( (a << 24) + (b << 16) + (g << 😎 + r )
else
return ( (r << 24) + (g << 16) + (b << 😎 + a )
end if
end function