我正在尝试在我的iOS应用程序using CIFilter中实现颜色选择器,并且必须解决同样的问题.
我发现给定颜色的HSV值非常适合该色轮:
>色调是车轮周围的角度. 0或1是0或2pi弧度,0.75是pi / 2,0.5是pi等.基本上,从最右边开始顺时针旋转从1到0.
>饱和度是指从圆心到边缘的距离,以半径的百分比表示.中间为0,边缘为1.
> value是颜色的暗度(我在上面链接的帖子中的inputValue).
因此,给定给定颜色的色调和饱和度,请参阅此伪代码:
float pickerWidth = myPickerImage.size.width;
float radius = pickerWidth / 2;
float colorRadius = saturation * radius;
float angle = (1 - hue) * (2 * pi);
float midX = myPicker.size.width / 2; //midpoint of the circle
float midY = myPicker.size.height / 2;
float xOffset = cos(angle) * colorRadius; //offset from the midpoint of the circle
float yOffset = sin(angle) * colorRadius;
Point colorPoint = new Point(midX + xOffset, midY + yOffset);
value参数将用于实现黑暗滑块.
你需要将RGB转换为HSV – UIColor会自动为我做这件事,但我敢打赌,在Android上也有办法做到这一点.