A T*_*hka 4 core-image uicolor ios swift
我有一个带有按钮的iOS绘图应用程序,让用户可以选择要绘制的颜色.由于我的画笔使用RGB值,但我的颜色常数是UIColors,我需要转换.我试过了
private var currentButton: UIButton? {
willSet{
currentButton?.layer.borderWidth = 0
}
didSet{
currentButton?.layer.borderWidth = 2
let index = (currentButton?.tag)! - 1
drawView.brush.blue = colors[index].ciColor.blue //Here is where I get the error
drawView.brush.green = colors[index].ciColor.green
drawView.brush.red = colors[index].ciColor.red
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在另一个StackOverflow问题中找到的.但是,当我尝试在第8行获取RGB值时,我收到此错误:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '*** -CIColor not defined for the UIColor UIExtendedSRGBColorSpace 1 1 1 1; need to first convert colorspace.'
Run Code Online (Sandbox Code Playgroud)
它清楚地说我需要转换色彩空间.但是CIColor.colorSpace只有获得.我究竟做错了什么?
用途getRed(_:green:blue:alpha:):
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
var alpha: CGFloat = 0
color.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3370 次 |
| 最近记录: |