Obtain a CGContextRef of NSView outside of drawRect?

て烟熏妆下的殇ゞ 提交于 2019-12-23 09:38:49

问题


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?


回答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



来源:https://stackoverflow.com/questions/1139330/obtain-a-cgcontextref-of-nsview-outside-of-drawrect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!