cocoa - Getting an image from NSGraphicsContext -
how can drawing in graphics context image?
if graphics port cgbitmapcontext, can create image that.
but that's not want rely on. if context's graphics port isn't cgbitmapcontext, you're screwed. moreover, there's no safe way tell whether it's cgbitmapcontext or not.
so, really, can't create image nsgraphicscontext.
this leads question of alternatives.
if it's nsview that's drawing context, problem solved: can ask view pdf of draws, , (if necessary) create image that. or, lock focus on view , create nsbitmapimagerep focused view. neither 1 of these work inside drawrect:
(the latter may work, wouldn't trust not call drawrect:
).
if think need image within drawrect:
in order rubber-stamp drawing multiple places, there 2 much-better solutions: move drawing code method , call every time need draw that, or create cglayer, draw image once it, , draw cglayer needed. drawing same thing repeatedly cglayers exist for.
Comments
Post a Comment