我正在尝试将UIImage效果类别从Objective-C转换为Swift语言。
当我尝试做某事时:
let inputImageBitmapInfo = CGImageGetBitmapInfo(inputCGImage)
let inputImageAlphaInfo = inputImageBitmapInfo & CGBitmapInfo.AlphaInfoMask
错误显示:
二元运算符'&'不能应用于两个
CGBitmapInfo
个操作数
Objective-C版本可以使用位掩码,但是Swift 不能。
Objective-C:
typedef CF_OPTIONS(uint32_t, CGBitmapInfo) {
kCGBitmapAlphaInfoMask = 0x1F,
kCGBitmapFloatInfoMask = 0xF00,
kCGBitmapFloatComponents = (1 << 8),
kCGBitmapByteOrderMask = 0x7000,
kCGBitmapByteOrderDefault = (0 << 12),
kCGBitmapByteOrder16Little = (1 << 12),
kCGBitmapByteOrder32Little = (2 << 12),
kCGBitmapByteOrder16Big = (3 << 12),
kCGBitmapByteOrder32Big = (4 << 12)
} CF_ENUM_AVAILABLE(10_4, 2_0);
夫特:
public struct CGBitmapInfo : OptionSetType {
public init(rawValue: UInt32)
public static var AlphaInfoMask: CGBitmapInfo { get }
public static var FloatInfoMask: CGBitmapInfo { get }
public static var FloatComponents: CGBitmapInfo { get }
public static var ByteOrderMask: CGBitmapInfo { get }
public static var ByteOrderDefault: CGBitmapInfo { get }
public static var ByteOrder16Little: CGBitmapInfo { get }
public static var ByteOrder32Little: CGBitmapInfo { get }
public static var ByteOrder16Big: CGBitmapInfo { get }
public static var ByteOrder32Big: CGBitmapInfo { get }
}