2014-08-29 117 views
0

使用ADTColor.RGBToHSV类型不匹配:不能从虚空转换为浮动[]

import android.graphics.Color; 

我不断收到一个Type mismatch: cannot convert from void to float[]Color.RGBToHSV(rgb[0], rgb[1], rgb[2], hsv);

float[] hsv = new float[3]; 

hsv = Color.RGBToHSV(rgb[0], rgb[1], rgb[2], hsv); 

错误路线与读取type mismatch。有没有办法解决?此代码以前是为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); 

任何帮助将不胜感激。

+0

java.awt.Color.RGBtoHSB的类型为float []和android.graphics.Color.RGBToHSV是类型空隙 – 2014-08-29 13:54:44

回答

0

这是从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); 
} 

这意味着它将RGB颜色HSV,并把它们在数组中。该方法不会返回任何东西,与java.awt.Color源代码相反

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[] VS void

0

它将这些值放入您作为参数传递的数组中。所以它的返回值类型实际上是void

+0

Color.RGBToHSV(RGB [0],RGB [1],RGB [2],HSV );在我的理解中不会被添加到数组中。我需要找到一种方法将这些值添加到hsv – 2014-08-29 13:58:33

相关问题