Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kCGImageAlphaNone unresolved identifier in swift

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.

like image 501
Kalzem Avatar asked Dec 12 '22 02:12

Kalzem


1 Answers

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)
like image 90
Martin R Avatar answered Dec 28 '22 07:12

Martin R