在drawRect外获得NSView的CGContextRef? [英] Obtain a CGContextRef of NSView outside of drawRect?
本文介绍了在drawRect外获得NSView的CGContextRef?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要获得NSView对象的CGContextRef。
I need to get CGContextRef of NSView object. It won't be so bad if I knew how.
在Carbon这个东西是这样做的:
In Carbon this thing was done like this:
CGContextRef cgref = (libvlc_drawable_t)GetWindowPort(HIViewGetWindow((OpaqueControlRef*)hiViewRef));
显然,它可以通过子类化NSView(或它的子类),并捕获它的drawRect,
Obviously it can be done by subclassing NSView (or it's subclass) and catching it in it's drawRect, but that's too ugly.
您的想法?
推荐答案
从未使用它,但它认为这是你的方式:
I've never used it but it think this is your way:
[myView lockFocus];
imageContext = (CGContextRef)[[NSGraphicsContext currentContext]
graphicsPort];
...
[myView unlockFocus];
也可以看看NSView的lockFocusIfCanDraw
also have a look to the lockFocusIfCanDraw of NSView
这篇关于在drawRect外获得NSView的CGContextRef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文