Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGBitMapContextCreate Method Causes Compiler Warning Xcode 5 not Xcode 4

I just updated Xcode from version 4.6.2 to 5.0, and after doing a method in my project (created in Xcode 4.6.2) is suddenly giving a compiler warning. I have tried re-opening the project in both the old and new versions of Xcode, and I have confirmed that the same method gives no warnings in 4.6.2.

Here is the line of code eliciting the warning in Xcode 5.0:

CGContextRef context = CGBitmapContextCreate(NULL, frame.size.width * scaleFactor, frame.size.height * scaleFactor, 8, frame.size.width * scaleFactor * 4, colorSpace, kCGImageAlphaPremultipliedFirst);

And the warning says:

"Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGBitMapInfo' (aka 'enum CGBitMapInfo')"

It does not appear to be a deprecation warning, but I am not quite familiar enough with these classes to interpret the meaning or know how to resolve it. Any help is appreciated.

like image 257
jac300 Avatar asked Sep 16 '13 14:09

jac300


2 Answers

The kCGImageAlpha* enum values are supposed to fill the first five bits in CGBitmapInfo. However, since the C type system can't express this, you get a warning that the types don't match, even though they were intended to.

The correct solution is to cast your alpha enum value to CGBitmapInfo, since that's what it is:

(CGBitmapInfo)kCGImageAlphaPremultipliedFirst
like image 191
nevyn Avatar answered Nov 02 '22 02:11

nevyn


Saw a comment https://github.com/inkling/Subliminal/issues/23 by aegolden that the intention of the new XCode warning might be directing you to use different masks on these enum types to construct and concatenate various flags. So instead of just using kCGImageAlphaPremultipliedFirst, use

(kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedFirst)

The warning will disappear after this change.

like image 34
CodeBrew Avatar answered Nov 02 '22 03:11

CodeBrew