Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGBitmapInfo swift what's new?

Just trying to use:

    var context = CGBitmapContextCreate(nil,
        self.bounds.width as UInt,
        self.bounds.height as UInt,
        8,
        nil,
        CGColorSpaceCreateDeviceRGB(),
        kCGBitmapByteOrder32Big)

But it says that kCGBitmapByteOrder32Big is unresolved identifier. But I found many examples like this in stackoverflow, but for objectiveC. Q: How to init/get CGBitmapInfo

The right syntax:

   var context:CGContextRef = CGBitmapContextCreate(nil,
        UInt(self.bounds.width),
        UInt(self.bounds.height),
        8,
        0,
        CGColorSpaceCreateDeviceRGB(),
        CGBitmapInfo.ByteOrder32Big)
like image 744
Olexiy Pyvovarov Avatar asked Sep 17 '14 14:09

Olexiy Pyvovarov


1 Answers

In Swift, this should be CGBitmapInfo.ByteOrder32Big. You can pass it as just .ByteOrder32Big because the type CGBitmapInfo is already known.

In general, ObjC/CoreFoundation enums in the form TypeValue or kTypeValue are Type.Value in Swift.

You're passing nil as bytesPerRow. I think you meant 0 here. nil is not the same thing (though it's probably working for you in ObjC).

like image 88
Rob Napier Avatar answered Sep 29 '22 05:09

Rob Napier