Swift OpenGL未解析的标识符kCGImageAlphaPremultipliedLast [英] Swift OpenGL unresolved identifier kCGImageAlphaPremultipliedLast
本文介绍了Swift OpenGL未解析的标识符kCGImageAlphaPremultipliedLast的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到'kCGImageAlphaPremultipliedLast'的未解决的标识符错误。斯威夫特找不到它。这在Swift中可用吗?
I am getting a unresolved identifier error for 'kCGImageAlphaPremultipliedLast'. Swift can't find it. Is this available in Swift?
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 }
// ...
}
其中可能的alpha info位被单独定义为枚举:
where the possible "alpha info" bits are defined separately as an enumeration:
enum CGImageAlphaInfo : UInt32 {
case None /* For example, RGB. */
case PremultipliedLast /* For example, premultiplied RGBA */
case PremultipliedFirst /* For example, premultiplied ARGB */
// ...
}
因此,您必须将枚举转换为其基础 UInt32
价值
,然后从中创建一个 CGBitmapInfo
:
Therefore you have have to convert the enum to its underlying UInt32
value
and then create a CGBitmapInfo
from it:
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue)
let gc = CGBitmapContextCreate(..., bitmapInfo)
Swift 2更新: CGBitmapInfo
定义更改为
public struct CGBitmapInfo : OptionSetType
并且可以用
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue)
这篇关于Swift OpenGL未解析的标识符kCGImageAlphaPremultipliedLast的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文