开发者

CGImage (or UIImage) from a CALayer

开发者 https://www.devze.com 2023-01-18 03:39 出处:网络
I have c开发者_JAVA技巧reated 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 refer

I have c开发者_JAVA技巧reated 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?


Try this...

UIGraphicsBeginImageContext(layer.bounds.size);
[layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


Create a bitmap graphics context and use renderInContext: to draw the layer into it. You now have the layer in an image.

0

精彩评论

暂无评论...
验证码 换一张
取 消