CGImage (or UIImage) from a CALayer

后端 未结 2 1646
迷失自我
迷失自我 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();
    

提交回复
热议问题