从视图层获取UIImage? [英] Get UIImage from view's layers?
本文介绍了从视图层获取UIImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的视图中包含内容为图像的子图层。
I have a view which has sublayers whose contents are images.
我希望通过myView.image获取视图的图像,但显然视图没有图像只是图层。
I was hoping to get the view's image by myView.image but apparently the view doesn't have image just layers.
如何从视图的图层创建UIImage?
How do I create a UIImage from view's layers?
推荐答案
UIGraphicsBeginImageContext(yourView.bounds.size);
[yourView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
注意:你需要包含QuartzCore。
Note: you need to include QuartzCore for this.
这篇关于从视图层获取UIImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文