的CGBitmapContextCreate()
最後一個參數被定義爲一個結構
struct CGBitmapInfo : RawOptionSetType {
init(_ rawValue: UInt32)
init(rawValue: UInt32)
static var AlphaInfoMask: CGBitmapInfo { get }
static var FloatComponents: CGBitmapInfo { get }
// ...
}
其中可能的 「阿爾法信息」 位作爲一個枚舉單獨定義:
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)
更新斯威夫特2:的CGBitmapInfo
定義改爲
public struct CGBitmapInfo : OptionSetType
,它可以與
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue)
感謝初始化你剛纔救了我大量的時間! – NJGUY 2014-10-29 20:54:36
@Martin R非常感謝! – BurtK 2016-03-27 13:34:01