一、问题描述

下载图片,然后用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的更多相关文章

  1. 一种解决的方法:CGContextSaveGState: invalid context 0x0

    遇到这个问题找了好久答案,最后排错排出来了 CGContextSaveGState: invalid context 0x0. This is a serious error. This applic ...

  2. 【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 ...

  3. 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 ...

  4. 关于CGContextSetBlendMode: invalid context 0x0的错误

    在ios 7的模拟器中,选择一个输入框准备输入时,会触发这个错误,以下是出错详细日志: <Error>: CGContextSetBlendMode: invalid context 0x ...

  5. iOS关于CGContextSetBlendMode: invalid context 0x0的错误

    在ios 7的模拟器中,选择一个输入框准备输入时,会触发这个错误,以下是出错详细日志: <Error>: CGContextSetBlendMode: invalid context 0x ...

  6. invalid context 0x0.

    在展示图片或者做二维码的时候,若是宽或者高有一个为零的情况就会报错:CGBitmapContextCreateImage: invalid context 0x0. If you want to se ...

  7. <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,默 ...

  8. 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 ...

  9. C++控制台闪回;编译器警告C4305,C4244

    这是我以前解决问题时,收集在印象笔记里的内容,为了以后整理方便,把它转移至这里.以下内容,均来自微软官方网站相关.     问题:C++控制台闪回     解决办法: 1,在程序结尾添加system( ...

随机推荐

  1. Django框架

    一.首先,到底什么是框架? 想要回答这个问题,我们要慢慢来. ①首先从DRY原则开始说起 Don't Repeat Yourself,不要重复你的代码. DRY原则的重要性怎么提都不过分,很多人说编程 ...

  2. php use memcached in ubuntu 14.04

    I assume you already had a lamp environment first step,we must to install memched in our Ubuntu Syst ...

  3. orcle函数的使用,及其调用

    CREATE OR REPLACE Function getBdateT( D_Build date, Q_Date date) return Date as D_Return Date; /*返回的 ...

  4. C#计算一段程序运行时间的三种方法

    第一种方法利用System.DateTime.Now: static void SubTest() { DateTime beforDT = System.DateTime.Now; //耗时巨大的代 ...

  5. Ubuntu下deb文件及tgz文件安装

    dpkg 是Debian Package的简写,是为Debian 专门开发的套件管理系统,方便软件的安装.更新及移除.所有源自Debian的Linux发行版都使用dpkg,例如Ubuntu.Knopp ...

  6. 2.7我们的第一个Java程序

    最后,让我们正式编一个程序(注释⑤).它能打印出与当前运行的系统有关的资料,并利用了来自Java标准库的System对象的多种方法.注意这里引入了一种额外的注释样式:“//”.它表示到本行结束前的所有 ...

  7. Linux指令

    文件指令 ls: ls -a :把隐藏的文件显示 ls -l  显示文件的详细信息 -lh  也是显示文件的详细信息,只是文件的大小是以k单位 ls -ld 显示指定目录下的信息 mkdir: mkd ...

  8. WebService的使用

    转载至http://blog.csdn.net/yexuanbaby/article/details/9029605/ 第一次选择WebService,是为了替代数据库远程连接.我们都知道当SQL允许 ...

  9. 【ASP.NET程序员福利】打造一款人见人爱的ORM(一)

          “很多人都不太认可以第三方ORM,因为考虑的点不够全面,没有大用户群体的ORM有保证,这点是不可否认确是事实.但是往往用户群体大的ORM又有不足之处,今天我们就来聊聊关于ORM的话题,打造 ...

  10. Sharp Memory LCD (ls013b7dh03)驱动

    网上找不到什么靠谱的资料,甚至我调好了夏普原厂和代理商还来找我要demo,  哎,苦逼的码农. lcd_main.c #include "ls013b7dh03.h" #inclu ...