编译器警告:CGContextSaveGState: invalid context 0x0
一、问题描述
下载图片,然后用Quartz2D绘制缩放的图片,运行无法显示图片并且编译器警告:
Aug 18 21:41:50 02_计算UITableViewCell的行高[16777] <Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Aug 18 21:41:50 02_计算UITableViewCell的行高[16777] <Error>: CGContextSetBlendMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Aug 18 21:41:50 02_计算UITableViewCell的行高[16777] <Error>: CGContextSetAlpha: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Aug 18 21:41:50 02_计算UITableViewCell的行高[16777] <Error>: CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Aug 18 21:41:50 02_计算UITableViewCell的行高[16777] <Error>: CGContextScaleCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Aug 18 21:41:50 02_计算UITableViewCell的行高[16777] <Error>: CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Aug 18 21:41:50 02_计算UITableViewCell的行高[16777] <Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

二、问题分析
有人说因为设置app的状态栏样式的使用了旧的方式,一般式iOS6的时候使用这种方式,iOS7、8也兼容,但是到了iOS9就报了警告。在info.plist里面设置了View controller-based status bar appearance为NO,要设置为YES。
但View controller-based status bar appearance设置YES后,问题还是没解决。
后来发现只要执行以下代码都会警告:
1 - (void)setImageView
2 {
3 NSString *url = @"http://ww3.sinaimg.cn/large/005P1ePojw1f6xzt7o6saj30go4w8wna.jpg";
4 // 设置图片
5 __weak typeof(self) weakSelf = self;
6 [self.imageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
7 // 开启图形上下文
8 UIGraphicsBeginImageContextWithOptions(weakSelf.size, YES, 0.0);
9 // 将下载完的image对象绘制到图形上下文
10 CGFloat width = weakSelf.size.width;
11 CGFloat height = width * 520 / 300;
12 [image drawInRect:CGRectMake(0, 0, width, height)];
13 // 获得图片
14 weakSelf.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
15 // 结束图形上下文
16 UIGraphicsEndImageContext();
17 }];
18 }
后来发现问题出现在这处: UIGraphicsBeginImageContextWithOptions(weakSelf.size, YES, 0.0);
因为weakSelf.size的值CGSizeMake(0, 0),导致错误。
三、问题解决
重新设置self.size的值。
编译器警告:CGContextSaveGState: invalid context 0x0的更多相关文章
- 一种解决的方法:CGContextSaveGState: invalid context 0x0
遇到这个问题找了好久答案,最后排错排出来了 CGContextSaveGState: invalid context 0x0. This is a serious error. This applic ...
- 【iOS】CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable
CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SH ...
- CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
最近在测试的过程中, 发现了SpringBoar的一个问题: SpringBoard[53] <Error>: CGContextTranslateCTM: invalid context ...
- 关于CGContextSetBlendMode: invalid context 0x0的错误
在ios 7的模拟器中,选择一个输入框准备输入时,会触发这个错误,以下是出错详细日志: <Error>: CGContextSetBlendMode: invalid context 0x ...
- iOS关于CGContextSetBlendMode: invalid context 0x0的错误
在ios 7的模拟器中,选择一个输入框准备输入时,会触发这个错误,以下是出错详细日志: <Error>: CGContextSetBlendMode: invalid context 0x ...
- invalid context 0x0.
在展示图片或者做二维码的时候,若是宽或者高有一个为零的情况就会报错:CGBitmapContextCreateImage: invalid context 0x0. If you want to se ...
- <Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
转自这里 出 错原因:设置app的状态栏样式的使用使用了旧的方式,在info.plist里面设置了View controller- based status bar appearance为NO,默 ...
- dwc_otg驱动 "BUG: sleeping function called from invalid context at mm/page_alloc.c"
方案商的开发板上otg功能只能做device,硬件看过后说没有5v供电,加上后能够识别U盘了,但是内核报了错 [ 3.264000] usb 2-1: new high-speed USB devic ...
- C++控制台闪回;编译器警告C4305,C4244
这是我以前解决问题时,收集在印象笔记里的内容,为了以后整理方便,把它转移至这里.以下内容,均来自微软官方网站相关. 问题:C++控制台闪回 解决办法: 1,在程序结尾添加system( ...
随机推荐
- xv6的作业翻译——作业1 - shell和系统调用
Xv6的lecture LEC 1 Operating systems L1: O/S overview L1:O/S概述 * 6.828 goals 6.828的目标 Understan ...
- 个人理解c#对称加密 非对称加密 散列算法的应用场景
c#类库默认实现了一系列加密算法在System.Security.Cryptography; 命名空间下 对称加密 通过同一密匙进行加密和解密.往往应用在内部数据传输情况下.比如公司a程序 和B程序 ...
- iOS静态库开发中对Bitcode的支持
1.bitcode bitcode是LLVM编译器将C/C++/OC/Swift等前端变成语言编译成多种不同芯片上的机器指令过程中的中间代码.并且这个中间代码是CPU无关的. 原本我们的APP里要包含 ...
- Python Logging模块的简单使用
前言 日志是非常重要的,最近有接触到这个,所以系统的看一下Python这个模块的用法.本文即为Logging模块的用法简介,主要参考文章为Python官方文档,链接见参考列表. 另外,Python的H ...
- 不要遍历dom
function selectProvince() { $.ajax( { type: "post", url: "/province/getStrType", ...
- MySQL性能调优my.cnf详解
[client] port = 3306 socket = /tmp/mysql.sock [mysqld] port = 3306 socket = /tmp/mysql.sock basedir ...
- js控制文本框只能输入中文、英文、数字与指定特殊符号.
先在'' 里输入 onkeyup="value=value.replace(/[^\X]/g,'')" 然后在(/[\X]/g,'')里的 X换成你想输入的代码就可以了, 中文u4 ...
- 【ASP.NET程序员福利】打造一款人见人爱的ORM(一)
“很多人都不太认可以第三方ORM,因为考虑的点不够全面,没有大用户群体的ORM有保证,这点是不可否认确是事实.但是往往用户群体大的ORM又有不足之处,今天我们就来聊聊关于ORM的话题,打造 ...
- Java集合之ArrayList
ArrayList ArrayList是最常见以及每个Java开发者最熟悉的集合类了,顾名思义,ArrayList就是一个以数组形式实现的集合,以一张表格来看一下ArrayList里面有哪些基本的元素 ...
- iOS视频边下边播--缓存播放数据流
实现视频边下边播,这里的边下边播不是单独开一个子线程去下载,而是把视频播放的数据给保存到本地.简而言之,就是使用一遍的流量,既播放了视频,也保存了视频. 用到的框架:<AVFoundation/ ...