Jump to content

HEX to RGB


Buffalo

Recommended Posts

Just in case anyone needs the opposite of this function:

function rgbToHex ( nR, nG, nB ) 
    local sColor = "#" 
    nR = string.format ( "%X", nR ) 
    sColor = sColor .. ( ( string.len ( nR ) == 1 ) and ( "0" .. nR ) or nR ) 
    nG = string.format ( "%X", nG ) 
    sColor = sColor .. ( ( string.len ( nG ) == 1 ) and ( "0" .. nG ) or nG ) 
    nB = string.format ( "%X", nB ) 
    sColor = sColor .. ( ( string.len ( nB ) == 1 ) and ( "0" .. nB ) or nB ) 
    return sColor 
end 

Link to comment
Just in case anyone needs the opposite of this function:
function rgbToHex ( nR, nG, nB ) 
    local sColor = "#" 
    nR = string.format ( "%X", nR ) 
    sColor = sColor .. ( ( string.len ( nR ) == 1 ) and ( "0" .. nR ) or nR ) 
    nG = string.format ( "%X", nG ) 
    sColor = sColor .. ( ( string.len ( nG ) == 1 ) and ( "0" .. nG ) or nG ) 
    nB = string.format ( "%X", nB ) 
    sColor = sColor .. ( ( string.len ( nB ) == 1 ) and ( "0" .. nB ) or nB ) 
    return sColor 
end 

eh

function rgb2hex(r,g,b) 
  return string.format("#%02X%02X%02X", r,g,b) 
end 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...