How do I take a "screenshot" of an NSView?

Debashis picture Debashis · Jul 15, 2010 · Viewed 8.8k times · Source

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?

Answer

Chuck picture Chuck · Jul 15, 2010
[[NSImage alloc] initWithData:[view dataWithPDFInsideRect:[view bounds]]];