Re: [Vala] Convert RGB color value to HEX
- From: Satyajit Sahoo <satyajit happy gmail com>
- To: Jonas Kulla <nyocurio gmail com>
- Cc: vala-list <vala-list gnome org>
- Subject: Re: [Vala] Convert RGB color value to HEX
- Date: Tue, 4 Sep 2012 03:28:28 +0530
Thanks for all the help. really grateful. Here is the code if someone wants
to review.
On Monday, September 3, 2012, Jonas Kulla wrote:
2012/9/3 Satyajit Sahoo <satyajit happy gmail com <javascript:;>>
Hi. I need to get color value in HEX in my vala program.
Basically, I get a color expression like this,
rgb(red, green, blue) or rgba(red, green, blue, alpha)
But I need to convert it into a format #rrggbb
I cannot seem to understand how to do it.
using Gtk;
using Gdk;
void main(string[] args)
{
Gtk.init(ref args);
var win = new Gtk.Window(Gtk.WindowType.TOPLEVEL);
win.destroy.connect(Gtk.main_quit);
var b = new ColorButton();
b.use_alpha = true;
b.color_set.connect( (b) =>
{
Gdk.RGBA c = b.get_rgba();
string s =
"#%02x%02x%02x%02x"
.printf((uint)(Math.round(c.red*255)),
(uint)(Math.round(c.green*255)),
(uint)(Math.round(c.blue*255)),
(uint)(Math.round(c.alpha*255)))
.up();
stdout.printf("%s\n", s);
});
win.add(b);
win.show_all();
Gtk.main();
}
--
Satyajit Sahoo
Blog - Funsurf <http://www.funsurf-blog.blogspot.com>
Profile - Facebook <http://facebook.com/satya164>,
Google+<http://plus.google.com/u/0/114564489020097923600>
Twitter - @satya164 <http://twitter.com/satya164>
Artwork - DeviantArt <http://satya164.deviantart.com>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]