Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain a CGContextRef of NSView outside of drawRect?

I need to get CGContextRef of NSView object. It won't be so bad if I knew how.

In Carbon this thing was done like this:

CGContextRef cgref = (libvlc_drawable_t)GetWindowPort(HIViewGetWindow((OpaqueControlRef*)hiViewRef));

Obviously it can be done by subclassing NSView (or it's subclass) and catching it in it's drawRect, but that's too ugly.

Your ideas?

like image 968
Maleev Avatar asked Jul 16 '09 18:07

Maleev


1 Answers

I've never used it but it think this is your way:

[myView lockFocus];
imageContext = (CGContextRef)[[NSGraphicsContext currentContext]
                                     graphicsPort];
... 
[myView unlockFocus];

also have a look to the lockFocusIfCanDraw of NSView

like image 185
IlDan Avatar answered Sep 19 '22 02:09

IlDan