美文网首页iOS的学习
UIGraphicsBeginImageContextWithO

UIGraphicsBeginImageContextWithO

作者: follow_er | 来源:发表于2022-03-01 15:34 被阅读0次

使用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()官方方法解释:
主要意思就是从堆栈顶部移除当前基于位图的图形上下文。

image.png

UIGraphicsBeginImageContext相当于调用了一次, UIGraphicsBeginImageContextWithOptions.两个方法不用重复调用
UIGraphicsBeginImageContext()方法介绍:
注意: 这个函数相当于调用UIGraphicsBeginImageContextWithOptions函数,不透明参数设置为NO,比例系数为1.0。
这个函数可以从你的应用程序的任何线程调用。

image.png

相关文章

网友评论

    本文标题:UIGraphicsBeginImageContextWithO

    本文链接:https://www.haomeiwen.com/subject/fnndrrtx.html