CGImage (or UIImage) from a CALayer

后端 未结 2 1641
迷失自我
迷失自我 2021-02-09 23:37

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.

相关标签:
2条回答
  • 2021-02-10 00:10

    Try this...

    UIGraphicsBeginImageContext(layer.bounds.size);
    [layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    0 讨论(0)
  • 2021-02-10 00:10

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

    0 讨论(0)
提交回复
热议问题