NSView Screenshots Using Cocoa

While hacking away with the iPhone SDK & Cocoa, I discovered (from Ryan Britton) this code to capture a NSView as a NSImage.


[code]

NSView *view = self;
[view lockFocus];
NSBitmapImageRep *bitmap = [[[NSBitmapImageRep alloc] initWithFocusedViewRect: [view bounds]] autorelease];
[view unlockFocus];

NSImage *image = [[[NSImage alloc] initWithSize: [view bounds].size] autorelease];
[image addRepresentation:bitmap];

[/code]


ref: http://lists.apple.com/archives/cocoa-dev/2005/Oct/msg00771.html

Other references: http://www.cocoadev.com/index.pl?ScreenShotCode

Comments

Popular posts from this blog

Text Sherlock the OpenGrok alternative (Source Code Search Engine)

Python SUDS with Windows Authentication (SOAP)

JotNow, my new blog