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)
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With