使用 Objective C 从 RGB 转换为 HSL
我对 Objective C 很陌生,但已经编程了一段时间了。我开始创建一个函数,可以从 RGB 转换为 HSL,然后再转换回来,但我感觉它太长并且方向错误。有谁知道执行此转换的简单方法?
I'm quite new to objective c but have been programming for a while. I started creating a function that would convert from RGB to HSL and back again but I get a feeling it is way too long and headed in the wrong direction. Does anyone know of a simple way to perform this conversion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以将 UIColor-HSVAdditions.h/.m 类别添加到您的应用程序中,以向 UIColor 添加一组操作来处理色调、饱和度和值。请参阅 http://bravobug.com/news/?p=448 和
这
还有 ArsTechnica 文章。
You can add the UIColor-HSVAdditions.h/.m category to your app to add a set of operations to UIColor for working with hue, saturation and value. See http://bravobug.com/news/?p=448 and
this
ArsTechnica article also.
这是我正在使用的:
以下是如何调用它:
Here's what I'm using:
And here's how to call it:
我想你可以使用 NSColor 。
再想一想,我不知道
NSColor
在 iPhone 框架中是否可用 - 没有UIColor
吗?不管怎样,我会留下这个答案,以防有人在寻找 OS X 解决方案时出现在这里。You can use
NSColor
, I think.On second thought, I don't know if
NSColor
is available in the iPhone frameworks or not - isn't there aUIColor
? Anyway I'll leave this answer in case someone searching for an OS X solution ends up here.iPhone SDK 中缺少 NSColor。您可以使用此实用程序在 RGB 空间和 HSL 空间之间进行相互转换:
https://github.com/alessani/ColorConverter< /a>
NSColor is missing in iPhone SDK. You can use this utility to convert from RGB to HSL space and back:
https://github.com/alessani/ColorConverter