只是尝试使用:
var context = CGBitmapContextCreate(nil,
self.bounds.width as UInt,
self.bounds.height as UInt,
8,
nil,
CGColorSpaceCreateDeviceRGB(),
kCGBitmapByteOrder32Big)
但是它说 kCGBitmapByteOrder32Big
是未解析的标识符。但是我在 stackoverflow 中发现了很多这样的例子,但是对于 objectiveC。 Q: 如何初始化/获取CGBitmapInfo
正确的语法:
var context:CGContextRef = CGBitmapContextCreate(nil,
UInt(self.bounds.width),
UInt(self.bounds.height),
8,
0,
CGColorSpaceCreateDeviceRGB(),
CGBitmapInfo.ByteOrder32Big)
最佳答案
在 Swift 中,这应该是 CGBitmapInfo.ByteOrder32Big
。您可以将它作为 .ByteOrder32Big
传递,因为类型 CGBitmapInfo
是已知的。
通常,TypeValue 或 kTypeValue 形式的 ObjC/CoreFoundation 枚举在 Swift 中是 Type.Value。
您将 nil
作为 bytesPerRow
传递。我想你在这里的意思是 0
。 nil
不是一回事(尽管它可能在 ObjC 中对您有用)。
关于xcode - CGBitmapInfo swift 有什么新功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25893098/