扫码关注官方订阅号
使用 CALayer 进行绘图,然后通过 renderInContext 和 UIGraphicsGetImageFromCurrentImageContext() 生成图片这一系列的操作可以在非主线程吗?(并非操作显示在View上的Layer)
CALayer
renderInContext
UIGraphicsGetImageFromCurrentImageContext()
ringa_lee
可以放在后台线程的。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),^{ CGSize constrainedSize = {100, 100}; UIGraphicsBeginImageContextWithOptions(constrainedSize, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); { [self.view.layer renderInContext:context]; } CGContextRestoreGState(context); UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); });
UI操作还是主线程的吧
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
可以放在后台线程的。
UI操作还是主线程的吧