L'ultimo parametro di CGBitmapContextCreate()
è definito come uno struct
struct CGBitmapInfo : RawOptionSetType {
init(_ rawValue: UInt32)
init(rawValue: UInt32)
static var AlphaInfoMask: CGBitmapInfo { get }
static var FloatComponents: CGBitmapInfo { get }
// ...
}
dove le possibili "info alfa" bit sono definiti separatamente come un'enumerazione:
enum CGImageAlphaInfo : UInt32 {
case None /* For example, RGB. */
case PremultipliedLast /* For example, premultiplied RGBA */
case PremultipliedFirst /* For example, premultiplied ARGB */
// ...
}
Pertanto è devono convertire l'enum nel valore UInt32
sottostante e quindi creare un CGBitmapInfo
da esso:
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue)
let gc = CGBitmapContextCreate(..., bitmapInfo)
Aggiornamento per Swift 2: La definizione CGBitmapInfo
cambiato in
public struct CGBitmapInfo : OptionSetType
e può essere inizializzato con
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue)
fonte
2014-10-29 20:44:32
Grazie mi hai appena salvato un sacco di tempo ! – NJGUY
@ Martin R Grazie! – BurtK