【问题标题】:Get RGB color of coordinates: Adobe Illustrator获取坐标的RGB颜色:Adobe Illustrator
【发布时间】:2017-04-19 00:31:17
【问题描述】:

我正在使用 ExtendScript 为 Adob​​e 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 中。

非常感谢您对该帖子的问题或翻译的解决方案。

【问题讨论】:

    标签: javascript adobe-illustrator extendscript


    【解决方案1】:

    [编辑:对于您的 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
    

    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
    

    【讨论】:

    • 无需道歉:其他人可能有同样的问题,确实在 Mac 上工作。
    • 感谢您的解决方案!我爱 mac,永远不会得到不同类型的计算机 :)
    • 嗯,这有点“平台主义者”,但我原谅你 :-) 很高兴你发现这很有帮助!
    【解决方案2】:

    是的,此解决方案不起作用,因为在 Illustrator 等矢量编辑器中,颜色应用于整个矢量项目(路径)而不是分隔像素。即使您在 illustrator 中使用像素图像,也没有脚本函数可以获取像素颜色。

    【讨论】:

    • 可能的解决方法是直接在 Photoshop 中打开矢量文件。
    【解决方案3】:

    我认为这可以通过相当可怕的解决方案来实现:

    • 光栅化画板。

    • 创建对象马赛克(其中一个图块 ~> 一个像素)。

    • 找出哪个图块位于给定坐标下方并选择其颜色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多