我在CMYK顏色空間中有CGImage(即CGColorSpaceGetModel在通過CGImageGetColorSpace查詢時返回kCGColorSpaceModelCMYK)。CGImageDestination將CMYK顏色空間保存爲RGB
但是,當我嘗試通過CGImageDestination進行保存時,它將轉換爲RGBColorSpace。我試圖設置正確的派系價值,但無濟於事。我怎麼知道這個?當我用預覽打開保存的圖像時,通用信息選項卡會告訴我'ColorModel:RGB'和'配置文件名稱:通用RGB配置文件'。如果我用CGImageSource打開保存的文件並讀出屬性,我會得到相同的結果(RGB顏色模型,通用RGB配置文件)。
現在,在我失去最後一根頭髮之前(單數),我的問題是:這是故意的嗎? ImageIO不能以RGB以外的格式保存圖像嗎?只是踢,我試着相同的L * a * b顏色空間,並有相同的結果。
這裏是我的節省代碼:
BOOL saveImage(CGImageRef theImage, NSURL *fileDestination, NSString *theUTI)
{
CGImageDestinationRef imageDestination = CGImageDestinationCreateWithURL((__bridge CFURLRef)fileDestination, (__bridge CFStringRef) theUTI, 1, nil);
// now assemble the dictionary for saving
NSMutableDictionary *theDict = nil;
theDict = [[NSMutableDictionary alloc] initWithCapacity:10];
[theDict setObject:[NSNumber numberWithFloat:hdpi] forKey: (id) kCGImagePropertyDPIHeight];
[theDict setObject:[NSNumber numberWithFloat:vdpi] forKey: (id) kCGImagePropertyDPIWidth];
}
// now make sure that we have the correct color space in the dictionary
NSString *colorModel = nil;
CGColorSpaceRef theColorSpace = CGImageGetColorSpace(theImage);
CGColorSpaceModel theModel = CGColorSpaceGetModel(theColorSpace);
switch (theModel) {
case kCGColorSpaceModelRGB:
colorModel = kCGImagePropertyColorModelRGB;
break;
case kCGColorSpaceModelLab:
colorModel = kCGImagePropertyColorModelLab;
break;
case kCGColorSpaceModelCMYK:
colorModel = kCGImagePropertyColorModelCMYK;
break;
default:
colorModel = kCGImagePropertyColorModelRGB;
break;
}
[theDict setObject:colorModel forKey:(id) kCGImagePropertyColorModel];
// Add the image to the destination, characterizing the image with
// the properties dictionary.
CGImageDestinationAddImage(imageDestination, theImage, (__bridge CFDictionaryRef) theDict); //properties);
BOOL success = (CGImageDestinationFinalize(imageDestination) != 0);
CFRelease(imageDestination);
return success;
}
一定有什麼明顯我俯瞰。我必須設置一些kCFSuperSecretProperty才能使其工作嗎?或者ImageIO不保存爲CMYK?
哦,我在OSX 10.7(獅子),如果這是一個因素,