CMYK カラー スペースの CGImage があります (つまり、CGColorSpaceGetModel は、CGImageGetColorSpace を介してクエリを実行すると、kCGColorSpaceModelCMYK を返します)。
しかし、CGImageDestination で保存しようとすると、RGBColorSpace に変換されてしまいます。正しい辞書の値を設定しようとしましたが、役に立ちませんでした。どうすればこれを知ることができますか? 保存した画像をプレビューで開くと、一般情報タブに「ColorModel:RGB」と「Profile Name: Generic RGB Profile」と表示されます。保存したファイルを 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 (Lion) を使用しています。