Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法对基元类型int调用getGreen()_Java_Android_Image Processing_Colors - Fatal编程技术网

Java 无法对基元类型int调用getGreen()

Java 无法对基元类型int调用getGreen(),java,android,image-processing,colors,Java,Android,Image Processing,Colors,因此,我继续使用我的应用程序从用户拍摄的图片中选择颜色,并返回RGB值。问题是,当我尝试获取颜色的绿色值时,会出现一个错误,错误是“无法在基元类型int上调用getGreen()。以下是我编写的代码: Bitmap bitmap = ((BitmapDrawable)iv.getDrawable()).getBitmap(); int touchedRGB = bitmap.getPixel(x,y); rgbvals.setText("Color Value" + "#"

因此,我继续使用我的应用程序从用户拍摄的图片中选择颜色,并返回RGB值。问题是,当我尝试获取颜色的绿色值时,会出现一个错误,错误是“无法在基元类型int上调用getGreen()。以下是我编写的代码:

Bitmap bitmap = ((BitmapDrawable)iv.getDrawable()).getBitmap(); 
int touchedRGB = bitmap.getPixel(x,y);          
rgbvals.setText("Color Value" + "#" + Integer.toHexString(touchedRGB));
rgbvals.setTextColor(touchedRGB);
int gval = touchedRGB.getgreen();
我还试图将最后一行写为

    String gval = Integer.toString(touchedRGB).getGreen();

当然,getGreen()只能用于int类型。提前感谢各位的帮助

您可以使用类的静态方法:

返回颜色int的绿色分量。这与 (颜色>>8)&0xFF

int gval=Color.green(GB)

错误如下:

touchedRGB.getgreen();
Java编译器试图说:


因为
inttouchedRGB=bitmap.getPixel(x,y)
touchedRGB是基元数据类型(它是整数),不能对基元数据类型调用方法,它们不是对象。

上次我检查基元时没有方法。你能进一步解释一下吗?我以前读过,但这对我来说真的没有意义(我正在从C语言过渡到Java语言,所以一些细微的差别有点奇怪),是的,你读过。要么测试你的代码,要么去读Java文档。@DavidWallace去读android文档。我道歉。我不知道android用户添加了一个完全不同的类,名为
Color
。您可能应该在回答中注意到,这必须是
android.graphics.Color
,而不是
java.awt.Color
。我将以同样的方式编辑我的答案。谢谢你教育我。好的,谢谢@ZouZou。我的答案不见了。我比你投的票高。我想我应该远离Android问题——从某种意义上说,它不是真正的Java。