将RGB tiff文件转换为CMYK macOS

时间:2018-04-05 17:37:43

标签: objective-c macos zxing core-image color-space

我有一个从ZXing条形码库获得的RGB CGImageRef,但是,我需要在CMYK Color Space中使用这个文件。我尝试使用Cocoa进行了多次尝试,但未成功。

我能得到的最接近的是用CMYK拍摄照片,但在转换过程中失去了透明度。透明度已经以某种方式转换为白色。

以下是我使用的代码:

NSImage * sourceImage = [[NSImage alloc] initWithContentsOfFile:finalPath.path];
NSBitmapImageRep * sourceImageRep = [[sourceImage representations] objectAtIndex:0];
NSColorSpace * targetColorSpace = [NSColorSpace genericCMYKColorSpace];
NSBitmapImageRep * targetImageRep = [sourceImageRep bitmapImageRepByConvertingToColorSpace:targetColorSpace
                                                                                   renderingIntent:NSColorRenderingIntentPerceptual];
NSData * data = [targetImageRep representationUsingType: NSTIFFFileType properties: nil];
[data writeToFile:finalPath.path atomically: NO];

结果:文件已转换为CMYK,但条形码失去了透明度。

0 个答案:

没有答案