iPhone无法创建CGBitmapContext

Mat*_*art 5 iphone xcode core-graphics

我在创建CGBitmapContext时遇到问题.

CGContextRef bitmapContext = CGBitmapContextCreate(nil, imageSize.width, imageSize.height, 8, imageSize.width * 4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst)
Run Code Online (Sandbox Code Playgroud)

当我正常运行我的应用程序时它会工作.但是当我在我的"测试应用程序"(一个将执行我的测试的正在运行的应用程序)中运行它时,上下文被记录为(null)并且我得到以下错误:

<Error>: CGContextSetFillColorWithColor: invalid context 0x0
<Error>: CGContextFillRects: invalid context 0x0
<Error>: CGContextDrawImage: invalid context 0x0
<Error>: CGContextDrawImage: invalid context 0x0
<Error>: CGBitmapContextCreateImage: invalid context 0x0
Run Code Online (Sandbox Code Playgroud)

我的应用程序没有崩溃.但显然有些不对劲.(我知道错误是通过使用nil上下文调用这些方法创建的).

Cos*_*que 7

当您尝试创建的位图大小为CGSizeZero时,通常会出现此错误.检查imageSize的实际值.

此外,您泄漏了传递给函数的CGColorSpaceRef.