Re: HTML hexidecimal code from NSColor
Re: HTML hexidecimal code from NSColor
- Subject: Re: HTML hexidecimal code from NSColor
- From: Scott Anguish <email@hidden>
- Date: Thu, 15 May 2003 23:00:09 -0400
multiply them by 255 before using the stringFormat:
[NSString stringWithFormat: @"%X%X%X", red * 255.0, green * 255.0, blue
* 255.0];
On Thursday, May 15, 2003, at 10:51 PM, Francisco Tolmasky wrote:
Given an NSColor object, how do I create a string with the HTML
hexadecimal color codes?
I tried this:
- (NSString *)colorString
{
float red, green, blue;
[[color colorUsingColorSpaceName: NSCalibratedRGBColorSpace]
getRed: &red green: &green blue: &blue alpha: nil];
return [NSString stringWithFormat: @"%X%X%X", red, green, blue];
}
This doesn't work though, since the numbers returned are between 0.0
and 1.0, not 0 and 255. Does anyone know how to get it to work?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.