views:

77

answers:

2

I need to take the contents of an NSView and put them in an NSImage, for an experimental project. Is this possible? I did some Googling, tried two methods that I found - but they didn't really work. Any suggestions?

+3  A: 
[[NSImage alloc] initWithData:[view dataWithPDFInsideRect:[view bounds]]];
Chuck
Thank you very much.
Debashis
+1 It's worth noting that, although this is the right way in general, there are some cases where it will not work, eg views like `NSOpenGLView` that have their own OpenGL rendering context. In that case you need to get the pixel data directly and create a bitmap rep from it, which is a bit less neat.
walkytalky