本文整理匯總了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;
}
示例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;
}
示例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);
}
}