AppKit.TextKit.Formatter.LanguageDescriptor.NSColorToHexString C# (CSharp) Méthode

NSColorToHexString() public méthode

Converts the given color into a web style hex string in the form #RRBBGG or optionally #RRBBGGAA.
public NSColorToHexString ( NSColor color, bool withAlpha ) : string
color NSColor The NSColor to convert.
withAlpha bool If set to true with the alpha (transparency) of the color will be /// included.
Résultat string
		public string NSColorToHexString(NSColor color, bool withAlpha) {
			//Break color into pieces
			nfloat red=0, green=0, blue=0, alpha=0;
			color.GetRgba (out red, out green, out blue, out alpha);

			// Adjust to byte
			alpha *= 255;
			red *= 255;
			green *= 255;
			blue *= 255;

			//With the alpha value?
			if (withAlpha) {
				return String.Format ("#{0:X2}{1:X2}{2:X2}{3:X2}", (int)alpha, (int)red, (int)green, (int)blue);
			} else {
				return String.Format ("#{0:X2}{1:X2}{2:X2}", (int)red, (int)green, (int)blue);
			}
		}