Sollyu

导航

 

本篇文章由:http://www.sollyu.com/cocos2d-x-2-0-4-ios7-image-loading-errors/

说明

错误提示

<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行

[cocos2d-x 2.0.4][iOS7]图片加载错误

// draw text
CGColorSpaceRef colorSpace  = CGColorSpaceCreateDeviceRGB();
CGContextRef context        = CGBitmapContextCreate(data,
                                                    dim.width,
                                                    dim.height,
                                                    8,
                                                    (int)dim.width * 4, // 此处为修改
                                                    colorSpace,
                                                    kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);

原理

因为 dim.width * 4 有可能不是整数,所以就来个强制类型转换。

posted on 2015-01-04 19:15  sollyu  阅读(221)  评论(0编辑  收藏  举报