ios - 构造绘制 CALayer 可以在后台线程吗?
本文介绍了ios - 构造绘制 CALayer 可以在后台线程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
使用 CALayer
进行绘图,然后通过 renderInContext
和 UIGraphicsGetImageFromCurrentImageContext()
生成图片这一系列的操作可以在非主线程吗?(并非操作显示在View上的Layer)
解决方案
可以放在后台线程的。
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();
});
这篇关于ios - 构造绘制 CALayer 可以在后台线程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文