Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGB
来源:互联网 发布:知乎石油出口禁令 编辑:程序博客网 时间:2024/06/10 18:20
在使用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。
<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
- Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGB
- Type mismatch: cannot convert from Enumeration<String> to Enumeration<Object>
- Implicit Primitive Type Conversion Rule
- Enumeration
- Enumeration
- enumeration
- Enumeration
- Enumeration
- Enumeration
- Enumeration
- Enumeration
- Enumeration
- Enumeration
- Enumeration
- error: conversion from 'const char [ ]' to non-scalar type
- 【IOS异常汇总】之 implicit conversion of Object-C pointer type"NSString *" to C pointer type "const void *"
- tableView上的按钮功能
- POJ 3667(线段树+lazy思想)
- {avl}
- Android最新源码4.3下载-教程 2013-11
- linux程序编译期加入编译时间和svn版本号
- Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGB
- hdu 1229 还是A+B
- C语言结构体的对齐原则
- mysql 把select结果保存为临时表,mysql中把查询结果输出到临时表
- 开发适配手机屏幕的网页注意问题
- Eclipse 编码区-保护色-快捷大全
- 使用EF Power Tools生成映射关系时候 参数错误 :0x80070057
- 关于主机多IP和服务端口绑定IP的研究
- 对操作系统一句话即可致命的普通语句!