说明
错误提示
<Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaPremultipliedLast; 1266 bytes/row.
解决
定位文件 CCimage.mm
并找到函数 _initWithString
函数原型
static bool _initWithString(const char * pText, cocos2d::CCImage::ETextAlign eAlign, const char * pFontName, int nSize, tImageInfo* pInfo)
找到代码
▼代码位置大约在301行
// draw text
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(data,
dim.width,
dim.height,
8,
(int)dim.width * 4, // 此处为修改
colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
原理
因为 dim.width * 4
有可能不是整数,所以就来个强制类型转换。