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:
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue)
let gc = CGBitmapContextCreate(..., bitmapInfo)
Swift 2 更新:CGBitmapInfo 定义更改为
public struct CGBitmapInfo : OptionSetType
它可以用初始化
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue)