當前位置: 首頁>>代碼示例>>Java>>正文


Java Color.getRGBComponents方法代碼示例

本文整理匯總了Java中java.awt.Color.getRGBComponents方法的典型用法代碼示例。如果您正苦於以下問題:Java Color.getRGBComponents方法的具體用法?Java Color.getRGBComponents怎麽用?Java Color.getRGBComponents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.Color的用法示例。


在下文中一共展示了Color.getRGBComponents方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sameColor

import java.awt.Color; //導入方法依賴的package包/類
private static boolean sameColor(Color c1, Color c2) {
    final float delta = 0.1f;

    float[] rgb1 = new float[4];
    float[] rgb2 = new float[4];

    rgb1 = c1.getRGBComponents(rgb1);
    rgb2 = c2.getRGBComponents(rgb2);

    for (int i = 0; i < rgb1.length; i++) {
        if (Math.abs(rgb1[i] - rgb2[i]) > delta) {
            return false;
        }
    }
    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:MultiReadTest.java

示例2: motionColor

import java.awt.Color; //導入方法依賴的package包/類
protected float[] motionColor(float x, float y, float saturation, float brightness) {
        float angle01 = (float) (Math.atan2(y, x) / (2 * Math.PI) + 0.5);
        // atan2 returns -pi to +pi, so dividing by 2*pi gives -.5 to +.5. Adding .5 gives range 0 to 1.
//                    angle01=.5f; // debug
        int rgbValue = Color.HSBtoRGB(angle01, saturation, brightness);
        Color color = new Color(rgbValue);
        float[] rgb = color.getRGBComponents(null);
        return rgb;
    }
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:10,代碼來源:AbstractMotionFlowIMU.java

示例3: actionPerformed

import java.awt.Color; //導入方法依賴的package包/類
public void actionPerformed(ActionEvent e) {
    // Read the current color from the text field.
    String spec = getSelectedColor().trim();
    String[] specArray = spec.split("[{},]");
    float red = 0f;
    float green = 0f;
    float blue = 0f;
    float alpha = 1.0f;
    // If any exceptions occur during the attempt to parse,
    // then just use the default color.
    try {
        int i = 0;
        // Ignore any blank strings that this simple parsing produces.
        while (specArray[i].trim().equals("")) {
            i++;
        }
        if (specArray.length > i) {
            red = Float.parseFloat(specArray[i]);
        }
        i++;
        while (specArray[i].trim().equals("")) {
            i++;
        }
        if (specArray.length > i) {
            green = Float.parseFloat(specArray[i]);
        }
        i++;
        while (specArray[i].trim().equals("")) {
            i++;
        }
        if (specArray.length > i) {
            blue = Float.parseFloat(specArray[i]);
        }
        i++;
        while (specArray[i].trim().equals("")) {
            i++;
        }
        if (specArray.length > i) {
            alpha = Float.parseFloat(specArray[i]);
        }
    } catch (Exception ex) {
        // Ignore and use default color.
    }
    Color newColor =
        JColorChooser.showDialog(
            Query.this,
            "Choose Background Color",
            new Color(red, green, blue, alpha));
    if (newColor != null) {
        float[] components = newColor.getRGBComponents(null);
        StringBuffer string = new StringBuffer("{");
        // Use the syntax of arrays.
        for (int j = 0; j < components.length; j++) {
            string.append(components[j]);
            if (j < components.length - 1) {
                string.append(",");
            } else {
                string.append("}");
            }
        }
        _entryBox.setText(string.toString());
        _notifyListeners(_name);
    }
}
 
開發者ID:OpenDA-Association,項目名稱:OpenDA,代碼行數:65,代碼來源:Query.java


注:本文中的java.awt.Color.getRGBComponents方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。