如何将CALayer转储到CGImageRef?

时间:2010-01-09 17:41:14

标签: objective-c cocoa core-animation core-graphics

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

1 个答案:

答案 0 :(得分:10)

CALayer采用renderInContext:方法,接受CGContextRef 渲染到上下文后,您可以通过调用CGImageRef获取CGBitmapContextCreateImage(CGContextRef context)

我已经回答了类似的问题here