实现方法:

NSView子类中加入:
[self lockFocus];
 
NSBitmapImageRep *bits;
bits = [[NSBitmapImageRep alloc]
                   initWithFocusedViewRect: [self bounds]];
[self unlockFocus];
 
这样就可以将其保存在NSImage中,或者保存为文件等。
 
如果你希望将图形保存为矢量信息,你可以使用 [self dataWithPDFInsideRect: [self bounds]] 然后建立一个NSPDFImageRep。不要使用NSEPSImageRep因为PS格式转换速度比较缓慢。