如何将CALayer转储到CGImageRef?

kod*_*odz 10 cocoa core-animation core-graphics objective-c

我有一些基于CoreAnimation的自定义UI.我想实现某些CALayers的鼠标拖动,我想将拖动图层的图像粘贴到光标上.问题是,我无法将CALayer(不是基于图像/ .contents)变成某种形式的图像 - 如CGImageRef或NSImage.有任何想法吗?

Tho*_*ing 10

CALayer有一个renderInContext:方法,它接受一个CGContextRef.
渲染到上下文后,您可以CGImageRef通过调用获得CGBitmapContextCreateImage(CGContextRef context).

我已在这里回答了类似的问题.