saving a layer tree to an image file...

With the advent of iPhone and Leopard CALayer - or whole layer trees - often get used in favor of NSViews. The CALayer and its subclasses offer many convenient ways of getting data displayed quickly and - since we all like eye candy - with subtle and less subtle animations. Blending in or out datasets of a complex graph using a fade effect for free is just nice.

While revamping bcAdmin, my biggest application so far, I decided to make use of layer trees to display calls of bats, activity diagrams and the such. After getting into the way layers are hosted, drawn and animated, I had all the tools to write classes for graphs like I never was able before. Or not that easily at least.

I need a print out....
... which was easy to get from a NSView. Not so easy from a view hosting (in any kind) layers. The images produced with the connivence methods for printing - the ones I used all the years before - produced rather empty images... Not finding a quick solution at first, I started to write a special class of one of my views for printing. After one day struggling I got excellent PDFs printed from the view again.

But!
I thought this can't be the way to go on, not in Cocoa land. By reading a couple of docsets a third or fourth time I stumbled over a method that sounded as if quite helpful for my printing or image file creation problem:

[CALayer renderInContext:] to the rescue
Just grab a CGContext - be it for printing or a bitmap context, render the layer tree into this context and proceed as usual. Awesomeness that i needed some time to discover.

Beliebte Posts aus diesem Blog

EEG, Grüne Energie und die Folgen

Swift 2, AudioConverter, Callback and Core Audio

Aussagekraft der 7-Tage-Inzidenz