iPhone无法创建CGBitmapContext [英] iPhone cannot create CGBitmapContext

查看:73
本文介绍了iPhone无法创建CGBitmapContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建CGBitmapContext时遇到问题。

I have a problem with creating a CGBitmapContext.

CGContextRef bitmapContext = CGBitmapContextCreate(nil, imageSize.width, imageSize.height, 8, imageSize.width * 4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst)

当我正常运行应用程序时有用。但是,当我在测试应用程序(将运行我的测试的正在运行的应用程序)中运行它时,上下文记录为(空),并且出现以下错误:

When I run my application normally it works. But when I run it in my 'Test application' (a running app that will perform my tests) the context is logged as (null) and I get the following errors:

<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

我的应用程序不会崩溃。但是显然有问题。 (我知道错误是通过在nil上下文中调用这些方法而产生的。)

My application doesn't crash. But apparently there is something wrong. (I know the errors are created by calling those methods with a nil context).

推荐答案

当您尝试创建的位图是CGSizeZero。检查imageSize的实际值。

This error often appears when the size of the bitmap you're trying to create is CGSizeZero. Check the actual value of imageSize.

此外,还泄漏了传递给函数的CGColorSpaceRef。

Besides, you leak the CGColorSpaceRef you pass into the function.

这篇关于iPhone无法创建CGBitmapContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆