Ios Swift OpenGL未解析标识符KCGIMAGEAlphaPremultipledLast
“KCGimageAlphaPremultipledLast”的标识符错误未解决。斯威夫特找不到它。这个有Swift吗Ios Swift OpenGL未解析标识符KCGIMAGEAlphaPremultipledLast,ios,swift,opengl-es,Ios,Swift,Opengl Es,“KCGimageAlphaPremultipledLast”的标识符错误未解决。斯威夫特找不到它。这个有Swift吗 var gc = CGBitmapContextCreate(&pixelData, width: width, height: height, bitsPerComponent: 8, bytesPerRow: width*4, imageCS, bitmapInfo: kCGImageAlphaPremultipliedLast); 苹果的文档建议使用CGImag
var gc = CGBitmapContextCreate(&pixelData, width: width, height: height, bitsPerComponent: 8, bytesPerRow: width*4, imageCS, bitmapInfo: kCGImageAlphaPremultipliedLast);
苹果的文档建议使用
CGImageAlphaInfo.premultipledast
CGBitmapContextCreate()的最后一个参数定义为结构
struct CGBitmapInfo : RawOptionSetType {
init(_ rawValue: UInt32)
init(rawValue: UInt32)
static var AlphaInfoMask: CGBitmapInfo { get }
static var FloatComponents: CGBitmapInfo { get }
// ...
}
其中,可能的“alpha-info”位单独定义为枚举:
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)
Swift 2的更新:CGBitmapInfo的定义更改为
public struct CGBitmapInfo : OptionSetType
它可以用
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue)
谢谢你帮我节省了很多时间@马丁:太好了,谢谢你!