[英]Cannot invoke getGreen() on the Primitive Type int
因此,我將繼續使用我的應用程序,以從用戶拍攝的照片中挑選顏色並返回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類型。 在此先感謝您的幫助!
錯誤在這里:
touchedRGB.getgreen();
Java編譯器嘗試說:
由於int touchedRGB = bitmap.getPixel(x,y);
touchedRGB是原始數據類型(它是整數),您不能在原始數據類型上調用方法,它們不是對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.