2016-12-04 67 views
0

我使用ExtendScript对JavaScript的工作了Adobe Illustrator的2015年有什么办法,我可以从下面的代码的坐标获得RGB值?获取坐标的RGB色彩:Adobe Illustrator中

// 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; 

我GOOGLE了不少,发现this。 但是,它不起作用,因为它是在2009年发布的,或者因为它是为了在Photoshop中。

甲解决问题的方法或柱的翻译,将不胜感激。

回答

2

[编辑:我很抱歉为您的ExtendScript问题提供AppleScript答案。我只是看着AS的问题,忘了我去了一个不同的部分。我只能希望你在Mac上。如果不是这样,我想我就吃掉我的downvotes哭泣。]

有一种变通方法。它的优点(以及它的部分解决方法)是它可以在所有应用程序中运行。缺点是,它需要Python(这应该是你的Mac上无论如何 - 很容易安装,如果没有),以及第三方软件(包括免费)两片,“checkModifierKeys”和“cliclick”。我一直在使用脚本,出现在我的脚本菜单多年。 蟒蛇部分说明如下:http://thechrisgreen.blogspot.com/2013/04/python-script-for-getting-pixel-color.html 该脚本可以保存,做出可执行文件和使用AS do shell script命令调用。 及其余部分,用于在屏幕上选择一个点并等待控制键被按下(这就是我的工作方式)非常简单。 基本checkModifierKeys部分(其等待,直到控制键被按下)是:

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 

的cliclick部分(其获得的坐标)是:

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 
+0

不需要道歉:其他人可能有相同的问题,而*在Mac上工作。 – usr2564301

+0

感谢您的解决方案!我爱苹果,永远不会得到一种不同的电脑:) – bearacuda13

+0

那么,这有点“平台主义”,但我原谅你:-)我很高兴你觉得这有帮助! – CRGreen

1

是,这种解决方案是不行的,因为在编辑矢量例如Illustrator,颜色被施加到载体产品(路径)上整体不分开的像素。即使你在illistrator中使用像素图像,也没有脚本函数来获取像素颜色。

+0

是否有任何解决方法? – bearacuda13

+1

可能的解决方法是直接在Photoshop中打开矢量文件。 – emax