Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGImage (or UIImage) from a CALayer

I have created a CALayer (I added several shapes to the layer, but ultimately, I have a single CALayer), and I am having a LOT of trouble adding it to a CGImage. I have found some references to [CALayer renderInContext:ctx], but I am not sure how to implement it.

Has anyone done this before?

like image 833
Brett Avatar asked Sep 28 '10 19:09

Brett


1 Answers

Try this...

UIGraphicsBeginImageContext(layer.bounds.size);
[layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
like image 99
Jordan Avatar answered Oct 30 '22 02:10

Jordan