Swift 2&3: How to Use CGBitmapContextCreate
Asked Answered
W

1

5

I have the following code:

let ref:CGContextRef = CGBitmapContextCreate(nil , 200, 130, CGImageGetBitsPerComponent(self.CGImage), 0, CGImageGetColorSpace(self.CGImage), CGImageGetBitmapInfo(self.CGImage))

The problem is that I get this error:

Expression does not conform to type 'NilLieralConvertible'

What should I pass in instead of nil for the first argument and why?

Weisbrodt answered 19/8, 2015 at 21:3 Comment(0)
C
12

The problem is the last argument. Make the last argument CGImageGetBitmapInfo(self.CGImage).rawValue.

Cementite answered 19/8, 2015 at 21:6 Comment(2)
It's because the nature of bitmask types has completely changed in Swift 2.0. And CGBitmapInfo is a bitmask type.Cementite
Works for Swift 3 tooWenzel

© 2022 - 2024 — McMap. All rights reserved.