使用 ApplescriptObjC 使用 NSColorSpace 和 iccProfileData 转换图像的颜色空间

Using ApplescriptObjC to convert color spaces of an image using NSColorSpace and iccProfileData

我有一些代码可以将图像色彩空间从 RGB 更改为 GenericCMYK 配置文件。我希望能够使用 ICC 配置文件将图像转换为 CMYK 色彩空间。在 Photoshop 中有一种方法可以做到这一点,但是当你处理 100 张图像时,这个过程会占用用户太多时间,我正在尝试创建一个 AppleScript droplet 来为他们做这个。

我已经查看了 NSColorspace 的页面,看起来有办法做到这一点。我只是不知道如何将此 Objective-C 转换为 ApplescriptObjC。下面是 NSColorSpace 中对 ICC 配置文件的两个引用: 初始化?(iccProfileData:数据) 在给定 ICC 配置文件的情况下初始化并 returns 一个 NSColorSpace 对象。 var iccProfileData:数据? 创建接收器的 ICC 配置文件数据。

这是感谢 Shane 在 Macscripter.net:

提供的代码
set theImage to (current application's NSImage's alloc()'s initWithContentsOfURL:theInput)
    set imageRep to (theImage's representations()'s objectAtIndex:0)
    set targetSpace to current application's NSColorSpace's genericCMYKColorSpace()
    set bitmapRep to (imageRep's bitmapImageRepByConvertingToColorSpace:targetSpace renderingIntent:(current application's NSColorRenderingIntentPerceptual))
    set theProps to (current application's NSDictionary's dictionaryWithObjects:{1.0, true} forKeys:{current application's NSImageCompressionFactor, current application's NSImageProgressive})
    set jpegData to (bitmapRep's representationUsingType:(current application's NSJPEGFileType) |properties|:theProps)
    set colorSpace to bitmapRep's colorSpaceName() as text
    (jpegData's writeToURL:theOutput atomically:true)

我只需要弄清楚如何将 ICC 配置文件作为 CMYK 转换过程的一部分,我相信在这行代码中会发生这种情况:

set targetSpace to current application's NSColorSpace's genericCMYKColorSpace()

谁能给我一些指导?

谢谢!

您正在查看 Swift 中的 NSColorSpace 文档。 AppleScriptObjC 是一个 Objective-C 桥梁,因此在 Objective-C 中查看文档更有意义(可以在页眉中设置语言),您的代码片段将变为

set targetSpace to current application's NSColorSpace's alloc's initWithICCProfileData:iccData

其中 iccData 是您要使用的 ICC 配置文件数据。