public String convertToARGB(int color) {
// alpha = Integer.toHexString(Color.alpha(color));
red = Integer.toString(Color.red(color));
green = Integer.toString(Color.green(color));
blue = Integer.toString(Color.blue(color));
// System.out.println(Color.red(color));
ColorR.setText(red);
ColorG.setText(green);
ColorB.setText(blue);
return "#" + red + green + blue;
}
public static int alpha(int color) {
return color >>> 24;}
/**
* Return the red component of a color int. This is the same as saying
* (color >> 16) & 0xFF
*/
public static int red(int color) {
return (color >> 16) & 0xFF;
}
/**
* Return the green component of a color int. This is the same as saying
* (color >> 8) & 0xFF
*/
public static int green(int color) {
return (color >> 8) & 0xFF;
}
/**
* Return the blue component of a color int. This is the same as saying
* color & 0xFF
*/
public static int blue(int color) {
return color & 0xFF;
}
这个博客展示了如何使用Java的Color类将整型颜色值转换为RGB,并分别获取红色、绿色和蓝色的十进制表示。代码中定义了两个方法,convertToARGB()用于将颜色值拆分为RGB,并返回一个表示这些颜色的十六进制字符串;alpha()方法则是获取颜色的透明度值。

2万+

被折叠的 条评论
为什么被折叠?



