CGBitmapInfo迅速推出新的内容?

时间:2014-09-17 14:17:28

标签: xcode bitmap swift

试图使用:

    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),
        8,
        0,
        CGColorSpaceCreateDeviceRGB(),
        CGBitmapInfo.ByteOrder32Big)

1 个答案:

答案 0 :(得分:5)

在Swift中,这应该是CGBitmapInfo.ByteOrder32Big。您可以将其作为.ByteOrder32Big传递,因为类型CGBitmapInfo已知。

通常,TypeValue或kTypeValue形式的ObjC / CoreFoundation枚举是Swift中的Type.Value。

您将nil传递为bytesPerRow。我想你的意思是0nil不是一回事(虽然它可能在ObjC中为你效劳)。