Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Find color's change in a NSString (attributed)




On 21.2.2006, at 10:59, Andrea Salomoni wrote:

Hi to all,

I already find the way to parse correctly the attributed string, and I can read the dictionary with NSColor key....
But the problem is the following:


My function returns me this line string: NSCalibratedRGBColorSpace 0.531465 1 0.821694 1

This is the output when logged to console, but the value in dictionary is in fact NSColor object. What you see above is the description of this object.


I need only the rgb value to convert it a a websafe color (or an html version of this color)....
I cannot use the method [myAttributesDictionary valueForKey:@"NSColor"]; because the string is filled with not only the rgb values....

This code snippet should get you RedGreenBlue components in float variables or error message if this is some incompatible color:


NSColor *color ;
NSColor *rgbColor ;
float r, g, b, a ;

color = [myAttributesDictionary valueForKey:@"NSColor"] ;
rgbColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] ;
if( rgbColor != nil ) {
  [rgbColor getRed:&r green:&g blue:&b alpha:&a] ;
}
else {
  NSLog( @"Can't get RGB components out of %@", color ) ;
}


izidor

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Find color's change in a NSString (attributed) (From: Andrea Salomoni <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.