I am trying to convert images/textures (for SpriteKit) to grayscale with CoreImage in Swift :
I found this answer : https://stackoverflow.com/a/17218546/836501 which I try to convert to swift for iOS7/8
But kCGImageAlphaNone
doesn't exist. Instead I can use CGImageAlphaInfo.None
but the function CGBitmapContextCreate()
doesn't like it as its last parameter. I am obliged to use the enum CGBitmapInfo
but there doesn't seem to be the kCGImageAlphaNone
equivalent inside.
This is the full line with the wrong parameter (last one) :
var context = CGBitmapContextCreate(nil, UInt(width), UInt(height), 8, 0, colorSpace, kCGImageAlphaNone)
I just need a way to convert UIImage to grayscale in Swift.
You have to create a struct CGBitmapInfo
from the CGImageAlphaInfo.None
value:
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.None.rawValue)
var context = CGBitmapContextCreate(nil, UInt(width), UInt(height), 8, 0, colorSpace, bitmapInfo)
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