2014-10-29 12 views
8

Viene visualizzato un errore di identificatore non risolto per "kCGImageAlphaPremultipliedLast". Swift non riesce a trovarlo. È disponibile in Swift?Identificatore non risolto Swift OpenGL kCGImageAlphaPremultipliedLast

var gc = CGBitmapContextCreate(&pixelData, width: width, height: height, bitsPerComponent: 8, bytesPerRow: width*4, imageCS, bitmapInfo: kCGImageAlphaPremultipliedLast); 

risposta

21

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) 
+1

Grazie mi hai appena salvato un sacco di tempo ! – NJGUY

+0

@ Martin R Grazie! – BurtK

Problemi correlati