iphone - 从 UIColor 中提取 RGB

标签 iphone core-graphics uicolor cgcolor

之前见过这个问题,但我的示例似乎不起作用。

const CGFloat *toCol = CGColorGetComponents([[UIColor greenColor] CGColor]);

用 GDB 查看该数组是空的。有什么提示吗?

最佳答案

您提供的代码示例应该可以工作。

试试这个:

UIColor uicolor = [[UIColor greenColor] retain];
CGColorRef color = [uicolor CGColor];

int numComponents = CGColorGetNumberOfComponents(color);

if (numComponents == 4)
{
  const CGFloat *components = CGColorGetComponents(color);
  CGFloat red = components[0];
  CGFloat green = components[1];
  CGFloat blue = components[2];
  CGFloat alpha = components[3];
}

[uicolor release];

关于iphone - 从 UIColor 中提取 RGB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/816828/

相关文章:

iphone - Uicolor 255背后的逻辑

iPhone、cocos2d坐标系

iphone - iphone 应用程序图像中的颜色替换

objective-c - 使用 ARC 绘制渐变时 CFArrayRef 和 NSArray 出现问题

ios - 即使在指定 Bundle 时,在 IBDesignable Views 中使用 Assets 目录中的命名颜色也会导致 IB 崩溃

swift - 如何创建多个缓存的 UIColor

iphone - 这个 Objective-C 嵌套 NSArray 会导致 iPhone 上的内存泄漏吗?

iPhone 项目未运行(多次)

ios - 为什么我不能删除或删除 iPhone/iPad 重复的企业应用程序图标副本?

iOS 重绘图像以防止延迟解压导致图像变大