Indigo Rose Software
  #1  
Old 07-23-2005
JimS's Avatar
JimS JimS is offline
Forum Member
 
Join Date: May 2003
Location: Pendleton, Oregon
Posts: 911
Hex 2 R,g,b

Does anyone know a formula for converting a Hex value or a Decimal value for a color, into the correct R,G,B color value?


.
__________________
Add-ons for AMS. Toolbar Buttons Galore, System Animations, the Window Construction Kit, and more.
Visit Acme-Tek
Reply With Quote
  #2  
Old 07-23-2005
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
I believe the script "rgb.lua" found in your AMS script gallery has a function to do that.
Reply With Quote
  #3  
Old 07-23-2005
JimS's Avatar
JimS JimS is offline
Forum Member
 
Join Date: May 2003
Location: Pendleton, Oregon
Posts: 911
Thanks Corey, that Lua script is similar to what I’m after, but not quite. It will let me go from R,G,B to Decimal, or from R,G,B to Hex, but I want to go in the other direction. I want to change Hex to R,G,B and/or Decimal to R,G,B



.
__________________
Add-ons for AMS. Toolbar Buttons Galore, System Animations, the Window Construction Kit, and more.
Visit Acme-Tek
Reply With Quote
  #4  
Old 07-23-2005
Worm Worm is offline
Indigo Rose Customer
 
Join Date: Jul 2002
Location: USA
Posts: 3,937
You can use this to get HEX to RGB, then use the other RGB.LUA to go from there

Code:
function Hex2RGB(sHexString)
	if String.Length(sHexString) ~= 6 then
		return 0,0,0
	else
		red = String.Left(sHexString,2)
		green = String.Mid(sHexString,3,2)
		blue = String.Right(sHexString,2)
		red = tonumber(red, 16).."";
		green = tonumber(green, 16).."";
		blue = tonumber(blue, 16).."";
		return red, green, blue
	end
end

red, green, blue = Hex2RGB("FFCCFF")
Dialog.Message("", red..", "..green..", "..blue)
Reply With Quote
  #5  
Old 07-23-2005
JimS's Avatar
JimS JimS is offline
Forum Member
 
Join Date: May 2003
Location: Pendleton, Oregon
Posts: 911
That’s it! Thank you so much. It is so cool to have smart friends like you guys, thanks.




.
__________________
Add-ons for AMS. Toolbar Buttons Galore, System Animations, the Window Construction Kit, and more.
Visit Acme-Tek
Reply With Quote
  #6  
Old 07-23-2005
Worm Worm is offline
Indigo Rose Customer
 
Join Date: Jul 2002
Location: USA
Posts: 3,937
one thing on that is that the LUA function returns a number (thanks Tig)

If you want the returned values to be numbers, remove the .."" in the function. Also as an after thought, you might want to return -1, -1, -1 if the Hex string isn't the correct length so you can test if the function was successful.

Code:
function Hex2RGB(sHexString)
	if String.Length(sHexString) ~= 6 then
		return -1, -1, -1
	else
		red = String.Left(sHexString,2)
		green = String.Mid(sHexString,3,2)
		blue = String.Right(sHexString,2)
		red = tonumber(red, 16);
		green = tonumber(green, 16);
		blue = tonumber(blue, 16);
		return red, green, blue
	end
end

red, green, blue = Hex2RGB("FFCCFF")
if red ~= -1 then
	Dialog.Message("", red..", "..green..", "..blue)
else
	Dialog.Message("","Function failed")
end
Reply With Quote
  #7  
Old 07-23-2005
JimS's Avatar
JimS JimS is offline
Forum Member
 
Join Date: May 2003
Location: Pendleton, Oregon
Posts: 911
Wow! Thanks again Worm, your kindness is amazing.

I had looked through the forums before I posted, and I noticed functions that convert in other directions, but I couldn’t find this one, the one I most needed. Your help on this is very much appreciated.


.
__________________
Add-ons for AMS. Toolbar Buttons Galore, System Animations, the Window Construction Kit, and more.
Visit Acme-Tek
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HEX to ASCII converter SUF6NEWBIE AutoPlay Media Studio 5.0 2 01-14-2005 06:14 PM
RGB to HEX jwarrent AutoPlay Media Studio 5.0 13 08-25-2004 05:49 PM
Program: Binary Hex and Decimal Converter Protocol AutoPlay Media Studio 5.0 Examples 3 07-15-2004 01:11 PM
Converting hex value to decimal...can we do this in SF6?? Martin_SBT Setup Factory 6.0 5 02-06-2003 03:22 PM
Hex Code replacing BaZZa101 AutoPlay Media Studio 4.0 1 01-06-2003 12:21 PM


All times are GMT -6. The time now is 07:37 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software