本文介绍了CIColor 到 UIColor ->未为 UIColor UIExtendedSRGBColorSpace 定义 CIColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 rgb-hex 颜色空间实现 CIColor,如下所示:

 let bottomColor = UIColor.init(red: 235/255, green: 250/255, blue: 255/255, alpha: 1.0).ciColor

但是,我一直遇到以下错误:

由于未捕获的异常而终止应用'NSInvalidArgumentException',原因:'*** -CIColor 未定义UIColor UIExtendedSRGBColorSpace 0.921569 0.980392 1 1;需要首先转换色彩空间.'

我不确定这是什么意思.如何解决这个问题?

解决方案

这会起作用:

let uiColor = UIColor.init(red: 235.0/255.0, green: 250.0/255.0, blue: 255.0/255.0, alpha: 1.0)让底部颜色 = CIColor(颜色:uiColor)

您还可以在 UIColor 上添加扩展:

extension UIColor {var coreImageColor: CIColor {返回 CIColor(颜色:自我)}var 组件:(红色:CGFloat,绿色:CGFloat,蓝色:CGFloat,alpha:CGFloat){让颜色 = coreImageColor返回 (color.red, color.green, color.blue, color.alpha)}}

然后通过以下方式调用它:

let bottomColor = UIColor.init(red: 235.0/255.0, green: 250.0/255.0, blue: 255.0/255.0, alpha: 1.0).coreImageColor

我在这个相关问题中找到的答案和解释.>

I'm trying to implement CIColor from rgb-hex colorspace as follows:

    let bottomColor = UIColor.init(red: 235/255, green: 250/255, blue: 255/255, alpha: 1.0).ciColor

However, I keep on hitting the following error:

I'm not sure what this means. How to fix this?

解决方案

this will work:

let uiColor = UIColor.init(red: 235.0/255.0, green: 250.0/255.0, blue: 255.0/255.0, alpha: 1.0)
let bottomColor = CIColor(color: uiColor)

You can also add an extension on UIColor:

extension UIColor {
    var coreImageColor: CIColor {
        return CIColor(color: self)
    }
    var components: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
        let color = coreImageColor
        return (color.red, color.green, color.blue, color.alpha)
    }
}

And then call it via:

let bottomColor = UIColor.init(red: 235.0/255.0, green: 250.0/255.0, blue: 255.0/255.0, alpha: 1.0).coreImageColor

The answer and explanation for which I found in this related question.

这篇关于CIColor 到 UIColor ->未为 UIColor UIExtendedSRGBColorSpace 定义 CIColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-21 05:08