只是尝试使用:
var context = CGBitmapContextCreate(nil,self.bounds.width as UInt,self.bounds.height as UInt,8,nil,CGColorSpaceCreateDeviceRGB(),kCGBitmapByteOrder32Big)
但它说kCGBitmapByteOrder32Big是未解析的标识符.但我在stackoverflow中找到了很多这样的例子,但是对于objectiveC.问:如何初始化/获取CGBitmapInfo
正确的语法:
var context:CGContextRef = CGBitmapContextCreate(nil,UInt(self.bounds.width),UInt(self.bounds.height),CGBitmapInfo.ByteOrder32Big)
解决方法
在Swift中,这应该是CGBitmapInfo.ByteOrder32Big.您可以将其作为.ByteOrder32Big传递,因为类型CGBitmapInfo已知.
通常,TypeValue或kTypeValue形式的ObjC/C++oreFoundation枚举是Swift中的Type.Value.
你传递nil为bytesPerRow.我觉得你的意思是0.零是不一样的(虽然它可能在ObjC中为你工作).