- (void)saveJPG:(NSView*)view withFileName:(NSString*)path{
//[_A4Paper lockFocus];
NSImage *image = [[NSImage alloc] initWithData:[_A4Paper dataWithPDFInsideRect:[_A4Paper bounds]]];//_A4Paper为主界面中的View
//[_A4Paper unlockFocus];
[image lockFocus];
//先设置 下面一个实例
NSBitmapImageRep *bits = [[NSBitmapImageRep alloc]initWithFocusedViewRect:[view frame]];
[image unlockFocus];
//再设置后面要用到得 props属性
NSDictionary *imageProps = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:0] forKey:NSImageCompressionFactor];
//之后 转化为NSData 以便存到文件中
NSData *imageData = [bits representationUsingType:NSPNGFileType properties:imageProps];
//设定好文件路径后进行存储就ok了
[imageData writeToFile:[path stringByExpandingTildeInPath]atomically:YES]; //保存的文件路径一定要是绝对路径,相对路径不行
}