Java Color.RGBToHSV类型不匹配:无法从void转换为float[]
使用ADTJava Color.RGBToHSV类型不匹配:无法从void转换为float[],java,android,arrays,colors,rgb,Java,Android,Arrays,Colors,Rgb,使用ADT import android.graphics.Color; 我不断遇到类型不匹配的问题:无法从void转换为float[] float[] hsv = new float[3]; hsv = Color.RGBToHSV(rgb[0], rgb[1], rgb[2], hsv); 错误行在Color.RGBToHSV(rgb[0],rgb[1],rgb[2],hsv)下高亮显示和读取类型不匹配。这有什么关系吗?这段代码以前是为JRE设置的,但我正在将其转换为ADT 以前它是这
import android.graphics.Color;
我不断遇到类型不匹配的问题:无法从void转换为float[]
float[] hsv = new float[3];
hsv = Color.RGBToHSV(rgb[0], rgb[1], rgb[2], hsv);
错误行在Color.RGBToHSV(rgb[0],rgb[1],rgb[2],hsv)下高亮显示代码>和读取类型不匹配
。这有什么关系吗?这段代码以前是为JRE设置的,但我正在将其转换为ADT
以前它是这样读的
hsv = java.awt.Color.RGBtoHSB(rgb[0], rgb[1], rgb[2], hsv);
如何更正此类型不匹配
我尝试过这种方法,但我需要将它添加到float[]hsv
数组中
Color.RGBToHSV(rgb[0], rgb[1], rgb[2], hsv);
任何帮助都将不胜感激。它将这些值放入作为参数传递的数组中。所以它的返回值类型实际上是void
这是来自android的源代码
public static void RGBToHSV(int red, int green, int blue, float hsv[]) {
if (hsv.length < 3) {
throw new RuntimeException("3 components required for hsv");
}
nativeRGBToHSV(red, green, blue, hsv);
}
public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals) {
float hue, saturation, brightness;
if (hsbvals == null) {
hsbvals = new float[3];
}
int cmax = (r > g) ? r : g;
if (b > cmax) cmax = b;
int cmin = (r < g) ? r : g;
if (b < cmin) cmin = b;
brightness = ((float) cmax) / 255.0f;
if (cmax != 0)
saturation = ((float) (cmax - cmin)) / ((float) cmax);
else
saturation = 0;
if (saturation == 0)
hue = 0;
else {
float redc = ((float) (cmax - r)) / ((float) (cmax - cmin));
float greenc = ((float) (cmax - g)) / ((float) (cmax - cmin));
float bluec = ((float) (cmax - b)) / ((float) (cmax - cmin));
if (r == cmax)
hue = bluec - greenc;
else if (g == cmax)
hue = 2.0f + redc - bluec;
else
hue = 4.0f + greenc - redc;
hue = hue / 6.0f;
if (hue < 0)
hue = hue + 1.0f;
}
hsbvals[0] = hue;
hsbvals[1] = saturation;
hsbvals[2] = brightness;
return hsbvals;
}
返回类型不同float[]
vsvoidjava.awt.Color.RGBtoHSB是float[]类型,android.graphics.Color.RGBToHSV是voidColor.RGBToHSV类型(rgb[0],rgb[1],rgb[2],hsv);据我所知,不会添加到数组中。我需要找到一种方法将这些值添加到hsv