Tag: nsbitmapimagerep

如何从NSImage保存PNG文件(视网膜问题)

我正在对图像进行一些操作,完成后我想将图像保存为PNG。 我正在做以下事情: + (void)saveImage:(NSImage *)image atPath:(NSString *)path { [image lockFocus] ; NSBitmapImageRep *imageRepresentation = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0.0, 0.0, image.size.width, image.size.height)] ; [image unlockFocus] ; NSData *data = [imageRepresentation representationUsingType:NSPNGFileType properties:nil]; [data writeToFile:path atomically:YES]; } 这个代码工作,但问题是与视网膜的Mac,如果我打印NSBitmapImageRep对象,我得到不同的大小和像素矩形,当我的图像保存在磁盘上,它的大小的两倍: $0 = 0x0000000100413890 NSBitmapImageRep 0x100413890 Size={300, 300} ColorSpace=sRGB IEC61966-2.1 colorspace BPS=8 BPP=32 Pixels=600×600 Alpha=YES Planar=NO Format=0 CurrentBacking=<CGImageRef: 0x100414830> 我绑到的像素大小强制不关心视网膜的规模,因为我想保留原来的大小: imageRepresentation.pixelsWide […]