本文整理汇总了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);
}
}