Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGB
2013-11-28 15:55
375 查看
在使用xcode5 sdk iOS7环境,创建图形上下文进行图形绘制,合并,裁剪,特效处理等时避免不了使用如下方法创建位图:
在 iOS7以前,是使用如下方法创建的:
CG_EXTERN CGContextRef CGBitmapContextCreate(void *data, size_t width,
size_t height, size_t bitsPerComponent, size_t bytesPerRow,
CGColorSpaceRef space,CGImageAlphaInfo bitmapInfo)
注意最后一个参数类型是 CGImageAlphaInfo 枚举类型中的kCGImageAlphaPremultipliedLast值。其整型值为1。
但是在iOS7版本中,这个最后的参会类型发生了变化。看一下定义:
CGContextRef CGBitmapContextCreate(void *data,size_t width,
size_t height,size_t bitsPerComponent,size_t bytesPerRow,
CGColorSpaceRef space,CGBitmapInfo
bitmapInfo)
很明显最后一个参数由CGImageAlphaInfo 变化为 CGBitmapInfo,看一下这个类型的定义
从头到尾没有发现值为1的枚举量值。故在使用的时候会出现如下警告:
Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGBitmapInfo' (aka 'enum CGBitmapInfo')
意思很明显不过,类型不匹配非法。
以下给出解决方法:
第一种方法,定义宏:
这样就会直接映射出一个值为1的宏,原有方法不用改变。
第二种方法:原理和第一个一样,目的 还是为了生产出一个为1的值,直接修改代码。
其实所有的做法,不外乎为了使这里的值为1,类型匹配。你也直接可以传1,不用麻烦的各种写代码。也可以直接进行类型强制转换,这个你随便。只是每个人的习惯不一样,故,如何解决,自己参考决定 。
在 iOS7以前,是使用如下方法创建的:
CG_EXTERN CGContextRef CGBitmapContextCreate(void *data, size_t width,
size_t height, size_t bitsPerComponent, size_t bytesPerRow,
CGColorSpaceRef space,CGImageAlphaInfo bitmapInfo)
注意最后一个参数类型是 CGImageAlphaInfo 枚举类型中的kCGImageAlphaPremultipliedLast值。其整型值为1。
<span style="font-size:14px;">typedef CF_ENUM(uint32_t, CGImageAlphaInfo) { kCGImageAlphaNone, /* For example, RGB. */ kCGImageAlphaPremultipliedLast, /* For example, premultiplied RGBA */ kCGImageAlphaPremultipliedFirst, /* For example, premultiplied ARGB */ kCGImageAlphaLast, /* For example, non-premultiplied RGBA */ kCGImageAlphaFirst, /* For example, non-premultiplied ARGB */ kCGImageAlphaNoneSkipLast, /* For example, RBGX. */ kCGImageAlphaNoneSkipFirst, /* For example, XRGB. */ kCGImageAlphaOnly /* No color data, alpha data only */ };</span>
但是在iOS7版本中,这个最后的参会类型发生了变化。看一下定义:
CGContextRef CGBitmapContextCreate(void *data,size_t width,
size_t height,size_t bitsPerComponent,size_t bytesPerRow,
CGColorSpaceRef space,CGBitmapInfo
bitmapInfo)
很明显最后一个参数由CGImageAlphaInfo 变化为 CGBitmapInfo,看一下这个类型的定义
<span style="font-size:14px;">typedef CF_OPTIONS(uint32_t, CGBitmapInfo) { kCGBitmapAlphaInfoMask = 0x1F, kCGBitmapFloatComponents = (1 << 8), kCGBitmapByteOrderMask = 0x7000, kCGBitmapByteOrderDefault = (0 << 12), kCGBitmapByteOrder16Little = (1 << 12), kCGBitmapByteOrder32Little = (2 << 12), kCGBitmapByteOrder16Big = (3 << 12), kCGBitmapByteOrder32Big = (4 << 12) } CF_ENUM_AVAILABLE(10_4, 2_0);</span>
从头到尾没有发现值为1的枚举量值。故在使用的时候会出现如下警告:
Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGBitmapInfo' (aka 'enum CGBitmapInfo')
意思很明显不过,类型不匹配非法。
以下给出解决方法:
第一种方法,定义宏:
<span style="font-size:14px;">#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 #define kCGImageAlphaPremultipliedLast (kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast) #else #define kCGImageAlphaPremultipliedLast kCGImageAlphaPremultipliedLast #endif</span>
这样就会直接映射出一个值为1的宏,原有方法不用改变。
第二种方法:原理和第一个一样,目的 还是为了生产出一个为1的值,直接修改代码。
<span style="font-size:14px;">#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 int bitmapInfo = kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast; #else int bitmapInfo = kCGImageAlphaPremultipliedLast; #endif CGContextRef context = CGBitmapContextCreate(nil, CGContexWith*2, 290.0*2, 8, 4*CGContexWith*2, colorSpace, bitmapInfo);</span>
其实所有的做法,不外乎为了使这里的值为1,类型匹配。你也直接可以传1,不用麻烦的各种写代码。也可以直接进行类型强制转换,这个你随便。只是每个人的习惯不一样,故,如何解决,自己参考决定 。
相关文章推荐
- Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGB
- Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGB
- gcc编译错误(invalid conversion from 'int' to enum)
- [C/C++]warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
- iOS开发 - "Cast from pointer to smaller type 'int' loses information” 解决办法
- Cast from pointer to smaller type 'int' loses
- 怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int3
- Conversion from string literal to 'char *' is deprecated 问题原因
- warning:deprecated conversion from string constant to 'char *'
- Xcode更新到5.1,"Cast from pointer to smaller type 'int' loses information” in EAGLView.mm
- implicit conversion loses integer precision :'long' to 'int'
- iOS开发 - "Cast from pointer to smaller type 'int' loses information” 解决办法
- 【他山之石】warning:deprecated conversion from string constant to 'char *'解决方案
- warning:deprecated conversion from string constant to 'char *'解决方案
- Conversion to Dalvik format failed with error 1 Type Unable to resolve target 'android-7'的解决办法
- warning: deprecated conversion from string constant to 'char*'
- 151223怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to
- warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
- invalid conversion from 'const char*' to char*
- xcode更新到5.1,"Cast from pointer to smaller type 'int' loses information” in EAGLView.mm