gpt4 book ai didi

iphone - 从 UIColor 中提取 RGB

转载 作者:行者123 更新时间:2023-12-03 18:08:42 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com