我正在使用 ExtendScript 处理 Adobe Illustrator 2015 的 JavaScript。有什么方法可以从下面代码中的坐标获取 RGB 值吗?
// declares a document
var doc = app.activeDocument;
// sets x and y coordinates to get color from
var xPosition = 70.0;
var yPosition = 64.0;
这就是需要做的工作:
// gets rgb values
double redValue = doc.getRGBColor(xPosition, yPosition).red;
double greenValue = doc.getRGBColor(xPosition, yPosition).red;
double blueValue = doc.getRGBColor(xPosition, yPosition).red;
我用谷歌搜索了很多,发现 this 。 但它不起作用,要么是因为它是在 2009 年发布的,要么是因为它本来应该在 Photoshop 中。
问题的解决方案或该帖子的翻译将不胜感激。
最佳答案
[编辑:我很抱歉为您的 ExtendScript 问题提供了本质上 AppleScript 的答案。我只是在看 AS 问题,忘记了我去了不同的部分。我只能希望你使用的是 Mac。如果没有,我想我只会吃掉我的反对票并哭泣。]
有一个解决方法。它的优点(以及它的解决方法本质的一部分)是它适用于所有应用程序。缺点是它需要 python(无论如何,它应该在你的 Mac 上 - 如果没有的话安装相当容易),以及两个第三方软件(都是免费的),“checkModifierKeys”和“cliclick”。多年来我一直在使用出现在脚本菜单中的脚本。
python部分描述如下:http://thechrisgreen.blogspot.com/2013/04/python-script-for-getting-pixel-color.html
可以使用 AS do shell script
命令保存该脚本、使其可执行并调用。
其余的,选择屏幕上的一个点并等待按下控制键(这就是我的工作原理)非常简单。
基本的 checkModifierKeys 部分(等待按下 Control 键)是:
set controlIsDown to false
repeat until (controlIsDown)
set initialCheck to ((do shell script "/usr/local/bin/checkModifierKeys control"))
if initialCheck = "1" then set controlIsDown to true
end repeat
点击部分(获取坐标)是:
set xyGrabbed to do shell script "/usr/local/bin/cliclick p"
这似乎是一个很长的路要走,但效果很好。我的版本使用此处理程序将 rgb 值转换为十六进制,这对我的目的很有用:
to makeHex(theNumber) --was anInteger
--Converts an unsigned integer to a two-digit hexadecimal value
set theResult to ""
repeat with theIndex from 1 to 0 by -1
set theBase to (16 ^ theIndex) as integer
if theNumber is greater than or equal to theBase then
set theMultiplier to ((theNumber - (theNumber mod theBase)) / theBase) as integer
set theResult to theResult & item theMultiplier of ¬
{1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"}
set theNumber to (theNumber - theBase * theMultiplier)
else
set theResult to (theResult & "0")
end if
end repeat
theResult
end makeHex
关于javascript - 获取坐标: Adobe Illustrator的RGB颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40960288/