获取坐标的 RGB 颜色:Adobe Illustrator
Get RGB color of coordinates: Adobe Illustrator
我正在使用 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。
但是,它不起作用,因为它是 post2009 年编辑的,或者因为它本来是要在 photoshop 中使用的。
问题的解决方案或翻译post将不胜感激。
是的,这个解决方案不起作用,因为在 Illustrator 等矢量编辑器中,颜色是整体应用于矢量项目(路径)而不是分离像素。即使您在 illistrator 中使用像素图像,也没有脚本函数来获取像素颜色。
[编辑:我很抱歉为您的 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
我认为它可以通过相当可怕的解决方案来实现:
栅格化 artrboard。
创建对象马赛克(其中一个图块 ~> 一个像素)。
找出哪个方块位于给定坐标下方并选择其颜色。
我正在使用 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。 但是,它不起作用,因为它是 post2009 年编辑的,或者因为它本来是要在 photoshop 中使用的。
问题的解决方案或翻译post将不胜感激。
是的,这个解决方案不起作用,因为在 Illustrator 等矢量编辑器中,颜色是整体应用于矢量项目(路径)而不是分离像素。即使您在 illistrator 中使用像素图像,也没有脚本函数来获取像素颜色。
[编辑:我很抱歉为您的 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
我认为它可以通过相当可怕的解决方案来实现:
栅格化 artrboard。
创建对象马赛克(其中一个图块 ~> 一个像素)。
找出哪个方块位于给定坐标下方并选择其颜色。