Get UIImage from presentation layers?

I have a view that has sublayers whose contents are images.

I was hoping to get a view image using myView.image, but apparently the view does not have only image layers.

How to create UIImage from presentation layers?

+8
iphone calayer uiimage
source share
2 answers
UIGraphicsBeginImageContext(yourView.bounds.size); [yourView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 

Note. To do this, you need to enable QuartzCore.

+19
source share
 CGRect myRect =CGRectMake(0, 0, 300, 300);// [self.view bounds]; UIGraphicsBeginImageContext(myRect.size); CGContextRef ctx = UIGraphicsGetCurrentContext(); [[UIColor blackColor] set]; CGContextFillRect(ctx, myRect); [self.view.layer renderInContext:ctx]; UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext(); 
+1
source share

All Articles