In your NSView subclass:[self lockFocus]; NSBitmapImageRep *bits; bits = [[NSBitmapImageRep alloc] initWithFocusedViewRect: [self bounds]]; [self unlockFocus];Then you can add it to anNSImage
or save it to a file, or whatever.If you want to retain the vectoritude of the drawing, you can use
[self dataWithPDFInsideRect: [self bounds]]
, and then make anNSPDFImageRep
. Avoid theNSEPSImageRep
since it makes a trip throughNSPDFImageRep
along with a slow PS to PDF conversion. (Thanks to Peter Hosey for the PDF hint)