【问题标题】:How to get a RGB value from Color variable如何从颜色变量中获取 RGB 值
【发布时间】:2014-06-21 17:32:35
【问题描述】:
JColorChooser.showDialog(tEkran, "Select a Color", selectedColorBG);

选择一种颜色后,我需要将其转移到 3 个变量。像这样:

colorR = selectedColorBG.getR

colorG = selectedColorBG.getG

colorB = selectedColorBG.getB

有什么办法吗?

【问题讨论】:

标签: java colors rgb


【解决方案1】:

看看java.awt.Color documentation 会回答你的问题:

int getAlpha()
    Returns the alpha component in the range 0-255.
int getBlue()
    Returns the blue component in the range 0-255 in the default sRGB space.
int getGreen()
    Returns the green component in the range 0-255 in the default sRGB space.
int getRed()
    Returns the red component in the range 0-255 in the default sRGB space.

【讨论】:

    【解决方案2】:

    必须处理返回值:

    Color selectedColor = JColorChooser.showDialog(tEkran, "Select the color", initialColor);
    int red = selectedColor.getRed();
    int green = selectedColor.getGreen();
    int blue = selectedColor.getBlue();
    

    【讨论】:

      【解决方案3】:

      JColorChooser 有一个 getColor 方法,它返回一个 Color,它分别有 getRedgetGreengetBlue 方法

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-12-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-25
        相关资源
        最近更新 更多