【问题标题】:Swift 2&3: How to Use CGBitmapContextCreateSwift 2&3:如何使用 CGBitmapContextCreate
【发布时间】:2015-11-13 08:25:00
【问题描述】:

我有以下代码:

let ref:CGContextRef = CGBitmapContextCreate(nil , 200, 130, CGImageGetBitsPerComponent(self.CGImage), 0, CGImageGetColorSpace(self.CGImage), CGImageGetBitmapInfo(self.CGImage))

问题是我得到了这个错误:

表达式不符合类型'NilLieralConvertible'

第一个参数我应该传入什么而不是 nil,为什么?

【问题讨论】:

    标签: ios swift3 swift2 cgbitmapcontextcreate


    【解决方案1】:

    问题在于 last 参数。使最后一个参数CGImageGetBitmapInfo(self.CGImage).rawValue

    【讨论】:

    • 这是因为位掩码类型的性质在 Swift 2.0 中完全改变了。而 CGBitmapInfo 是位掩码类型。
    • 也适用于 Swift 3
    猜你喜欢
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-19
    • 1970-01-01
    • 2017-02-17
    • 2017-07-26
    相关资源
    最近更新 更多