<Error>: CGBitmapContextCreateImage: invalid context 0x0. 解决方案
2016-02-24 14:43
411 查看
阐述
最近研究 AVAssetReader+AVAssetReaderTrackOutput
用其写自己的视频播放类。编写中CMSampleBufferRef转换
CGImageRef 的时候产生一些 Error,如下方:
<Error>: CGBitmapContextCreateImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental
variable.
<Error>: CGBitmapContextCreateImage: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation
of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
相关代码
研讨
出现这类型错误,多半是创建内容画布的时候,height or width = 0, 因此在逻辑上添加判断(排除产生height or width
= 0 的情况),可以消除这种错误。
资料
1. http://stackoverflow.com/questions/19377299/cgcontextsavegstate-invalid-context
2. http://www.4byte.cn/question/425886/cgcontextsavegstate-invalid-context.html
最近研究 AVAssetReader+AVAssetReaderTrackOutput
用其写自己的视频播放类。编写中CMSampleBufferRef转换
CGImageRef 的时候产生一些 Error,如下方:
<Error>: CGBitmapContextCreateImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental
variable.
<Error>: CGBitmapContextCreateImage: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation
of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
相关代码
- (CGImageRef)imageFromSampleBuffer:(CMSampleBufferRef)sampleBuffer { CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); // Lock the base address of the pixel buffer CVPixelBufferLockBaseAddress(imageBuffer, 0); // Get the number of bytes per row for the pixel buffer size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); // Get the pixel buffer width and height size_t width = CVPixelBufferGetWidth(imageBuffer); size_t height = CVPixelBufferGetHeight(imageBuffer); //Generate image to edit unsigned char* pixel = (unsigned char *)CVPixelBufferGetBaseAddress(imageBuffer); CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceRGB(); CGContextRef context=CGBitmapContextCreate(pixel, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little|kCGImageAlphaPremultipliedFirst); CGImageRef image = CGBitmapContextCreateImage(context); CGContextRelease(context); CGColorSpaceRelease(colorSpace); return image; }
研讨
出现这类型错误,多半是创建内容画布的时候,height or width = 0, 因此在逻辑上添加判断(排除产生height or width
= 0 的情况),可以消除这种错误。
资料
1. http://stackoverflow.com/questions/19377299/cgcontextsavegstate-invalid-context
2. http://www.4byte.cn/question/425886/cgcontextsavegstate-invalid-context.html
相关文章推荐
- 访问Nginx发生SSL connection error的一种情况
- 星外虚拟主机访问被控出现Unspecified error解决方法
- IIS 错误 Server Application Error 详细解决方法
- On Error Resume Next 语句
- IIS运行错误 Server Application Error 错误代码 Error: 8004的解决方法
- Lua编程示例(一):select、debug、可变参数、table操作、error
- 收集整理的http/1.1 500 server error错误的解决方法
- SQL 2005 ERROR:3145 解决办法(备份集中的数据库备份与现有的数据库不同)
- VBScript中On Error语句用法小结
- 解决VC++编译报错error C2248的方案
- jQuery Uploadify 上传插件出现Http Error 302 错误的解决办法
- JQuery ajax中error返回错误及一直返回error的解答
- PHP函数之error_reporting(E_ALL ^ E_NOTICE)详细说明
- node.js使用npm 安装插件时提示install Error: ENOENT报错的解决方法
- PHP 5.3和PHP 5.4出现FastCGI Error解决方法
- 解决mysql ERROR 1017:Can't find file: '/xxx.frm' 错误
- MYSQL ERROR 1045 (28000): Access denied for user (using password: YES)问题的解决
- vs2012 error c4996: This function or variable may be unsafe
- php异常:Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE eval()'d code error
- ERROR/AndroidRuntime(17121)的问题解决