CGBitmapInfo fast, 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 he says kCGBitmapByteOrder32Big is an unresolved identifier. But I found many examples like this in stackoverflow, but for objectC. Q: How to start / get CGBitmapInfo

The correct syntax is:

  var context:CGContextRef = CGBitmapContextCreate(nil, UInt(self.bounds.width), UInt(self.bounds.height), 8, 0, CGColorSpaceCreateDeviceRGB(), CGBitmapInfo.ByteOrder32Big) 
+5
source share
1 answer

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

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

You pass nil like bytesPerRow . I think you meant 0 here. nil is not the same thing (although it probably works for you in ObjC).

+5
source

Source: https://habr.com/ru/post/1202774/


All Articles