使用ApplescriptObjC使用NSColorSpace和iccProfileData转换图像的色彩空间 [英] Using ApplescriptObjC to convert color spaces of an image using NSColorSpace and iccProfileData

查看:163
本文介绍了使用ApplescriptObjC使用NSColorSpace和iccProfileData转换图像的色彩空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码可以将图像的色彩空间从RGB更改为GenericCMYK配置文件。我希望能够使用ICC配置文件将图像转换为CMYK色彩空间。在Photoshop中可以执行此操作,但是当您处理100幅图像时,该过程会花费大量用户时间,我正在尝试创建一个AppleScript小滴来为他们完成此操作。

I have some code that will change an images colorspace from RGB to a GenericCMYK profile. I would like to be able to use an ICC Profile to convert the image to a CMYK colorspace. There is a way to do this in Photoshop, but the process takes too much of a users time when you are dealing with 100's of images, I am trying to create an AppleScript droplet that will do this for them.

我已经看过NSColorspace的页面了,看来有一种方法可以做到这一点。我只是不知道如何将该Objective-C转换为ApplescriptObjC。以下是对NSColorSpace中ICC配置文件的两个引用:
init?(iccProfileData:Data)
初始化并返回给定ICC配置文件的NSColorSpace对象。
var iccProfileData:数据?
创建接收方的ICC配置文件数据。

I have already looked at the page for NSColorspace and there looks like there is a way to do this. I just have no idea how to convert this Objective-C into ApplescriptObjC. Here are the two references to the ICC Profiles in NSColorSpace: init?(iccProfileData: Data) Initializes and returns an NSColorSpace object given an ICC profile. var iccProfileData: Data? The ICC profile data from which the receiver was created.

以下是我在Macscripter.net上感谢Shane编写的代码:

Here is the code I have thanks to Shane at 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转换过程的一部分:

I just need to figure out how to include the ICC Profile as a part of the CMYK conversion process that happens I believe on this line of code:

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

有人可以给我一些指导吗?

Can anyone give me some guidance on this?

谢谢!

推荐答案

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

You are looking at the NSColorSpace documentation in Swift. AppleScriptObjC is an Objective-C bridge, so it makes more sense viewing the documentation in Objective-C (the language can be set in the page header), where your snippet becomes

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

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

where iccData is the ICC profile data you are going to use.

这篇关于使用ApplescriptObjC使用NSColorSpace和iccProfileData转换图像的色彩空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆