使用UIGraphicsBeginImageContextWithOptions截图
- (UIImage *)captureGenerateImage {
UIGraphicsBeginImageContextWithOptions(self.ivTemplate.bounds.size, self.ivTemplate.opaque, [UIScreen mainScreen].scale);
// UIGraphicsBeginImageContext(self.ivTemplate.bounds.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[self.ivTemplate.layer renderInContext:ctx];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// [self.layer renderInContext:UIGraphicsGetCurrentContext()];
return image;
}
调用UIGraphicsBeginImageContextWithOptions
必须调用UIGraphicsEndImageContext
,否则会造成内存泄漏。
UIGraphicsEndImageContext()
官方方法解释:
主要意思就是从堆栈顶部移除当前基于位图的图形上下文。
UIGraphicsBeginImageContext
相当于调用了一次, UIGraphicsBeginImageContextWithOptions
.两个方法不用重复调用
UIGraphicsBeginImageContext()
方法介绍:
注意: 这个函数相当于调用UIGraphicsBeginImageContextWithOptions函数,不透明参数设置为NO,比例系数为1.0。
这个函数可以从你的应用程序的任何线程调用。
网友评论