Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dump CALayer into CGImageRef?

I have some custom, CoreAnimation based UI. I'd like to implement mouse dragging of certain CALayers and I'd like to stick an image of dragged layer to the cursor. The problem is, that I can't get the CALayer (which isn't image/.contents based) into an image of some kind - like CGImageRef or NSImage. Any ideas?

like image 962
kodz Avatar asked Jan 09 '10 17:01

kodz


1 Answers

CALayer has a renderInContext: method, which accepts a CGContextRef.
After rendering to the context, you can obtain a CGImageRef by calling CGBitmapContextCreateImage(CGContextRef context).

I already answered a similar question here.

like image 190
Thomas Zoechling Avatar answered Oct 08 '22 03:10

Thomas Zoechling