Javascript 获取坐标的RGB颜色:Adobe Illustrator
我正在使用ExtendScript为Adobe Illustrator 2015开发JavaScript。有没有办法从下面代码中的坐标中获取RGB值Javascript 获取坐标的RGB颜色:Adobe Illustrator,javascript,adobe-illustrator,extendscript,Javascript,Adobe Illustrator,Extendscript,我正在使用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
// 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;
我在谷歌上搜索了不少,找到了。
不过,它不起作用,要么是因为它是在2009年发布的,要么是因为它本来应该放在photoshop中
如果您能解决此问题或翻译此文章,我们将不胜感激。是的,此解决方案不起作用,因为在Illustrator等矢量编辑器中,颜色总体上应用于矢量项(路径),而不是分离像素。即使您在illistrator中使用像素图像,也没有获取像素颜色的脚本函数 是的,此解决方案不起作用,因为在Illustrator等向量编辑器中,颜色总体上应用于向量项(路径),而不是分离像素。即使您在illistrator中使用像素图像,也没有获取像素颜色的脚本函数 [编辑:我很抱歉对你的ExtendScript问题给出了一个基本的AppleScript答案。我只是作为问题看了一下,忘了我去了另一个部分。我只能希望你在Mac上。如果不是,我想我会吃了我的反对票,然后哭泣。] 有一个变通办法。它的优点(以及它的一部分变通性质)是它适用于所有应用程序。缺点是它需要python(不管怎样,它应该在你的Mac上——如果没有,安装起来相当容易),以及两个第三方软件(都是免费的),“checkModifierKeys”和“cliclick”。多年来,我一直在使用出现在脚本菜单中的脚本。 python部分如下所述: 可以使用AS
do shell脚本
命令保存、执行和调用此脚本。
剩下的,在屏幕上选择一个点,等待控制键被按下(这就是我的工作原理)是非常简单的。
基本checkModifierKeys部分(等待控制键按下)为:
cliclick部件(获取坐标)为:
这似乎是一个很长的路要走,但它的工程伟大。我的版本使用此处理程序将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
[编辑:我很抱歉对你的ExtendScript问题给出了一个基本的AppleScript答案。我只是作为问题看了一下,忘了我去了另一个部分。我只能希望你在Mac上。如果不是,我想我会吃了我的反对票,然后哭泣。] 有一个变通办法。它的优点(以及它的一部分变通性质)是它适用于所有应用程序。缺点是它需要python(不管怎样,它应该在你的Mac上——如果没有,安装起来相当容易),以及两个第三方软件(都是免费的),“checkModifierKeys”和“cliclick”。多年来,我一直在使用出现在脚本菜单中的脚本。 python部分如下所述: 可以使用AS
do shell脚本
命令保存、执行和调用此脚本。
剩下的,在屏幕上选择一个点,等待控制键被按下(这就是我的工作原理)是非常简单的。
基本checkModifierKeys部分(等待控制键按下)为:
cliclick部件(获取坐标)为:
这似乎是一个很长的路要走,但它的工程伟大。我的版本使用此处理程序将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
我认为这可以通过一个相当可怕的解决方案来实现:
- 将纸板光栅化
- 创建对象马赛克(其中一个平铺~>一个像素)
- 找出哪一块瓷砖位于给定坐标下,并选择其颜色
- 将纸板光栅化
- 创建对象马赛克(其中一个平铺~>一个像素)
- 找出哪一块瓷砖位于给定坐标下,并选择其颜色
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