Swift OpenGL 未解析的标识符 kCGImageAlphaPremultipliedLast [英] Swift OpenGL unresolved identifier kCGImageAlphaPremultipliedLast

查看:20
本文介绍了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

The last parameter of CGBitmapContextCreate() is defined as a struct

struct CGBitmapInfo : RawOptionSetType {
    init(_ rawValue: UInt32)
    init(rawValue: UInt32)

    static var AlphaInfoMask: CGBitmapInfo { get }
    static var FloatComponents: CGBitmapInfo { get }
    // ...
}

其中可能的alpha 信息"位被单独定义为枚举:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆