Swift OpenGL未解析标识符kCGImageAlphaPremultipliedLast
问题描述:
我收到'kCGImageAlphaPremultipliedLast'的未解决标识符错误。 Swift找不到它。这在Swift中可用吗?Swift OpenGL未解析标识符kCGImageAlphaPremultipliedLast
var gc = CGBitmapContextCreate(&pixelData, width: width, height: height, bitsPerComponent: 8, bytesPerRow: width*4, imageCS, bitmapInfo: kCGImageAlphaPremultipliedLast);
答
的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)
答
Apple文档建议CGImageAlphaInfo.PremultipliedLast
。
感谢初始化你刚才救了我大量的时间! – NJGUY 2014-10-29 20:54:36
@Martin R非常感谢! – BurtK 2016-03-27 13:34:01