The last parameter of CGBitmapContextCreate()
is defined as a struct
struct CGBitmapInfo : RawOptionSetType {
init(_ rawValue: UInt32)
init(rawValue: UInt32)
static var AlphaInfoMask: CGBitmapInfo { get }
static var FloatComponents: CGBitmapInfo { get }
// ...
}
where the possible "alpha info" bits are defined separately as an enumeration:
enum CGImageAlphaInfo : UInt32 {
case None /* For example, RGB. */
case PremultipliedLast /* For example, premultiplied RGBA */
case PremultipliedFirst /* For example, premultiplied ARGB */
// ...
}
Therefore you have have to convert the enum to its underlying UInt32
value
and then create a CGBitmapInfo
from it:
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue)
let gc = CGBitmapContextCreate(..., bitmapInfo)
Update for Swift 2: The CGBitmapInfo
definition changed to
public struct CGBitmapInfo : OptionSetType
and it can be initialized with
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue)