[Mono-list] Best way to convert Cairo.Color from/to Gdk.Color???
monkey at jpobst.com
Sun Nov 21 11:33:25 EST 2010
Here are the extension methods I use to convert back and forth. Note
that the range of a Cairo color value is 0.0-1.0 and the range for Gdk
public static Cairo.Color ToCairoColor (this Gdk.Color color)
return new Cairo.Color ((double)color.Red / ushort.MaxValue,
(double)color.Green / ushort.MaxValue, (double)color.Blue /
public static Gdk.Color ToGdkColor (this Cairo.Color color)
Gdk.Color c = new Gdk.Color ();
c.Blue = (ushort)(color.B * ushort.MaxValue);
c.Red = (ushort)(color.R * ushort.MaxValue);
c.Green = (ushort)(color.G * ushort.MaxValue);
On 11/21/2010 6:40 AM, Francisco M. Marzoa wrote:
> I'd like to know what's the best way to converting Cairo.Color into
> Gdk.Color and viceversa, mainly for using Gtk.ColorSelection widget.
> Currently I'm doing something like:
> Gdk.Color gcl;
> Cairo.Color ccl;
> gcl = Gdk.Color ( (byte)ccl.R, (byte)ccl.G, (byte),cc.B);
> Although it seems to work, it does not looks neither clean nor robust,
> as Cairo.Color uses a double for each color component, data may be lost
> on the conversion though. I wonder if there's a better method for doing
> this, and also for converting from Gdk.Color to Cairo.Color.
> Thanks a lot in advance.
> Best regards,
> Mono-list maillist - Mono-list at lists.ximian.com
More information about the Mono-list