Objective c 将NSBItmapImageRep保存为不带alpha的灰度png

Objective c 将NSBItmapImageRep保存为不带alpha的灰度png,objective-c,cocoa,image-processing,Objective C,Cocoa,Image Processing,我尝试在没有alpha通道的情况下保存NSBItmapImageRep。 我的代码是: NSBitmapImageRep* rep = [[NSBitmapImageRep alloc] initWithCIImage:img]; NSColorSpace *targetColorSpace = [NSColorSpace genericGrayColorSpace]; NSBitmapImageRep *targetImageRep = [rep bitmapImageRepByConvert

我尝试在没有alpha通道的情况下保存NSBItmapImageRep。 我的代码是:

NSBitmapImageRep* rep = [[NSBitmapImageRep alloc] initWithCIImage:img];
NSColorSpace *targetColorSpace = [NSColorSpace genericGrayColorSpace];
NSBitmapImageRep *targetImageRep = [rep bitmapImageRepByConvertingToColorSpace:targetColorSpace 
                                                               renderingIntent:NSColorRenderingIntentPerceptual];

NSData* PNGData = [targetImageRep representationUsingType:NSPNGFileType properties:nil];
[PNGData writeToURL:url atomically:YES];    
[rep release];
但它不起作用。它使用类型GrayScaleAlpha保存我的图像。
如何指定使用alpha

我认为如果不使用外部库,这是不可能的。所有灰度颜色空间都包含Cocoa中的alpha组件,而且似乎也没有任何选项可以在ImageIO中保存无alpha的PNG。谢谢您的帮助。你节省了我的时间)哦,那石英2D框架呢。正如我所看到的,我可以通过这个来实现吗?严格来说,Quartz2D根本不支持保存图像,这是ImageIO的领域(
CGImageDestinationRef
),正如我所说,我认为它不支持这一点。