UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()]; //截图
UIImage *tempImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
在本代码中,有两个需要注意的有可能关系到内存的问题
- 内存问题,不会产生在
UIGraphicsGetImageFromCurrentImageContext()这行代码中
因为
UIGraphicsGetImageFromCurrentImageContext()返回的是一个autorelease的UIImage对象
- 一定要对应
UIGraphicsBeginImageContextWithOptions()和UIGraphicsEndImageContext ()
因为
UIGraphicsBeginImageContextWithOptions()会在函数体内部通过
CGBitmapContetAlloc内部函数分配内存空间,而UIGraphicsEndImageContext ()的作用就是释放该空间。