1

NSColor を ccColor3B に変換するにはどうすればよいですか? NSColor は任意の色空間にある可能性があるため、 redComponent などが機能しない場合があります。

4

2 に答える 2

1

うまくいくかどうかはわかりませんが、試すことができます:

    NSColor *color = [NSColor redColor];

    CGFloat red, green, blue;

    [color getRed:&red green:&green blue:&blue alpha:NULL];

    ccColor3B cccolor = {red / 255.0f, green / 255.0f, blue / 255.0f};
于 2013-09-12T08:09:44.010 に答える
1

何だと思いますか、私はこれをdocsで見つけました。

Can I Access the Components of Any NSColor Object?

It is invalid to use an accessor method related to components of a particular color space on an NSColor object that is not in that color space. For example, NSColor methods such as redComponent and getRed:green:blue:alpha: work on color objects in the calibrated and device RGB color spaces. If you send such a message to an NSColor object in the CMYK color space, an exception is raised.

If you have an NSColor object in an unknown color space and you want to extract its components, you should first convert the color object to a known color space before using the component accessor methods of that color space. For example:

NSColor *aColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
if (aColor) {
    float rcomp = [aColor redComponent];
}
If the color is already in the requested color space, you get back the original object.

とにかくありがとう ;-)

だから私の場合、私は今これを使用しています:

NSColor *colorConverted = [self._color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
if (colorConverted) {
    self.labelFormac.color = ccc3(colorConverted.redComponent * 255.0f, colorConverted.greenComponent * 255.0f, colorConverted.blueComponent * 255.0f);
}
于 2013-09-13T01:10:07.510 に答える