【问题标题】:How to create an array of RBG colors?如何创建 RGB 颜色数组?
【发布时间】:2014-02-01 02:23:44
【问题描述】:

我已经导入了 java.awt.Color;但找不到一种方法,我可以在 0 -255 范围内写入 3 个颜色分量值(红色、绿色、蓝色)。这不可能吗?如果没有,如何轻松创建颜色数组?

import java.awt.Color;

【问题讨论】:

    标签: java arrays colors


    【解决方案1】:

    构造函数呢

    Color(int r, int g, int b, int a)
    Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255).
    

    Color(int r, int g, int b)
    Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255).
    

    ?

    new Color(255,255,255); //white
    

    【讨论】:

      【解决方案2】:

      你只需要创建一个新的颜色:

      Color a = new Color(arg0, arg1, arg2); //arg0 = red, arg1 = green, arg2 = blue
      

      【讨论】:

        【解决方案3】:

        只需使用这个 Color 构造函数和 getRGB() 方法来获取颜色:

        Color color = new Color(int r, int g, int b);
        color.getRGB();
        

        【讨论】:

          【解决方案4】:

          使用Color的构造函数Color(int r, int g, int b)(见here

          【讨论】:

            猜你喜欢
            • 2016-08-19
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-05-27
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-12-01
            相关资源
            最近更新 更多