NSColorWell

Discussion in 'Mac Programming' started by varsis, Jan 13, 2008.

  1. varsis macrumors regular

    Joined:
    Nov 30, 2005
    #1
    Hi,

    I am currently making a plugin, and it uses HEX values for color (It goes on the internet.)

    The code I am using looks like this:
    Code:
    NSColor *myColor = [userColor color];
    	float redPart = [myColor redComponent];
    	float greenPart = [myColor greenComponent];
    	float bluePart = [myColor blueComponent];
    	int redHexString = redPart * 255;
    	int greenHexString = greenPart * 255;
    	int blueHexString = bluePart * 255;
    	NSString *rgbHexString = [NSString stringWithFormat:@"0x%.2x%.2x%.2x", redHexString, greenHexString, blueHexString];
    	NSString *rgbString = [NSString stringWithFormat:@"%.2x%.2x%.2x", redHexString, greenHexString, blueHexString];
    Problem is the user can use CKMY,grayscale... etc... how do I convert these to Hex? Or only allow hex?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    I'm not really sure what you mean here. Are you referring to the NSColor object you're getting from the color well?
     
  3. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #3
    Let NSColor convert to RGB space for you. From the Color Programming Topics docs (link off the NSColor API reference):

    I think you'd probably want to use "device" RGB space to avoid values changing with calibration, but I'm not sure what the usage is.
     

Share This Page