I need to get CGContextRef of NSView object. It won't be so bad if I knew how.
我需要获取NSView对象的CGContextRef。如果我知道如何,情况就不会那么糟糕。
In Carbon this thing was done like this:
在Carbon这个事情是这样做的:
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.
显然,它可以通过继承NSView(或它的子类)并在它的drawRect中捕获它来完成,但这太难看了。
Your ideas?
1 个解决方案
#1
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
另外看看NSView的lockFocusIfCanDraw
#1
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
另外看看NSView的lockFocusIfCanDraw