Swift OpenGL未parsing标识符kCGImageAlphaPremultipliedLast
我收到'kCGImageAlphaPremultipliedLast'未解决的标识符错误。 Swift找不到它。 这在Swift中可用吗?
var gc = CGBitmapContextCreate(&pixelData, width: width, height: height, bitsPerComponent: 8, bytesPerRow: width*4, imageCS, bitmapInfo: kCGImageAlphaPremultipliedLast);
CGBitmapContextCreate()
的最后一个参数被定义为一个结构体
struct CGBitmapInfo : RawOptionSetType { init(_ rawValue: UInt32) init(rawValue: UInt32) static var AlphaInfoMask: CGBitmapInfo { get } static var FloatComponents: CGBitmapInfo { get } // ... }
其中可能的“alpha信息”位分别定义为枚举:
enum CGImageAlphaInfo : UInt32 { case None /* For example, RGB. */ case PremultipliedLast /* For example, premultiplied RGBA */ case PremultipliedFirst /* For example, premultiplied ARGB */ // ... }
因此,您必须将枚举转换为其基础UInt32
值,然后CGBitmapInfo
创build一个CGBitmapInfo
:
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue) let gc = CGBitmapContextCreate(..., bitmapInfo)
Swift 2更新: CGBitmapInfo
定义更改为
public struct CGBitmapInfo : OptionSetType
并可以用它初始化
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue)
Apple文档build议使用CGImageAlphaInfo.PremultipliedLast
。