我有一些自定义的、基于 CoreAnimation 的 UI。我想实现某些 CALayers 的鼠标拖动,我想将拖动图层的图像粘贴到光标上。问题是,我无法将 CALayer(不是基于 image/.contents 的)放入某种图像中——比如 CGImageRef 或 NSImage。有什么想法吗?
最佳答案
CALayer 有一个 renderInContext:方法,它接受一个 CGContextRef
。
渲染到上下文后,您可以通过调用 CGBitmapContextCreateImage(CGContextRef context)
获得一个 CGImageRef
。
我已经回答过类似的问题here .
关于objective-c - 如何将 CALayer 转储到 CGImageRef 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2034261/