GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Nov 22, 2014 3:03 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Convert GdkRGBA to Hex Color Code
PostPosted: Mon May 19, 2014 7:57 pm 
Offline

Joined: Tue May 06, 2014 12:25 am
Posts: 4
How does one convert a GdkRGBA color:

Code:

typedef struct {
  gdouble red; //all values between 0.0 and 1.0
  gdouble green;
  gdouble blue;
  gdouble alpha;
} GdkRGBA;



back to a hex code?:

Code:
RGB = (R*65536)+(G*256)+B , (when R is RED, G is GREEN and B is BLUE)


Since each color in the GtkRGBA struct is a number between 0.0 and 1.0 I'm not sure how to convert back to a hex string or int value of the color. I've tried this for instance ( just a guess ):

Code:
GdkRGBA c;
.....
colorInt = ( c.red * 256 ) * 65536 + ( c.green * 256 ) * 256 + ( c.blue * 256 );//does not seem to work


Thanks for any input.......


Top
 Profile  
 
 Post subject: Re: Convert GdkRGBA to Hex Color Code
PostPosted: Tue May 20, 2014 12:07 am 
Offline

Joined: Tue May 06, 2014 12:25 am
Posts: 4
It seems I forgot to cast the floating point value to an int. This seems to work:

Code:
colorInt = ( ( int ) ( c.red * 256 ) ) * 65536 + (  ( int ) ( c.green * 256 )  ) * 256 + ( ( int )  ( c.blue * 256 ) );//does seem to work


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group