将NSColor转换为RGB [英] Convert NSColor to RGB

查看:234
本文介绍了将NSColor转换为RGB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将NSColor转换为RGB,但似乎给出了完全不正确的结果:

I'm trying to convert an NSColor to RGB, but it seems to give an entirely incorrect result:

NSColor *testColor = [NSColor colorWithCalibratedWhite:0.65 alpha:1.0];

const CGFloat* components = CGColorGetComponents(testColor.CGColor);
NSLog(@"Red: %f", components[0]);
NSLog(@"Green: %f", components[1]);
NSLog(@"Blue: %f", components[2]);
NSLog(@"Alpha: %f", CGColorGetAlpha(testColor.CGColor));

我回来了:红色= 0.65-绿色= 1.0-蓝色= 0.0和alpha是1.0-导致完全不同的颜色。 (应该是灰色,现在是绿色)。

I get back : red = 0.65 - green = 1.0 - blue = 0.0 and alpha is 1.0 - which results in an entirely different color. (It should be gray, now it's green).

我做错了吗?

推荐答案

您需要使用 NSColorSpace 对象,然后您可以使用各种 NSColor 访问器方法

You need to convert the color to an RGB color space using an NSColorSpace object first, then you can get the components using the various NSColor accessor methods

这篇关于将NSColor转换为RGB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆