2013-04-02 28 views
-2

今天我收到了一個錯誤,我無法解釋我正在看notch的視頻,他正在創建2d遊戲HerpFortress(http://pt.twitch.tv/notch/b/309642636(0:42:44)),而我正在關注他的代碼,但是此行中我得到,我得到一個throught錯誤...Java圖像錯誤

img.getRGB(x * sw, y * sh, sw, sh, result [x][y].pixels, 0, sw); 

和錯誤是,

The method getRGB(int, int, int, int, int[], int, int) in the type BufferedImage is not applicable for the arguments (int, int, int, int, int, int, int) 

幫助?

+0

第5個參數應該是一個數組。你已經提供了一個int。這裏是[BufferedImage]的文檔(http://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html) – jahroy

+0

哥們它是一個數組 – MysteryGuy

+1

不,它不是。否則,你不會得到那個錯誤。它看起來像你正在引用一個數組給我。 – jahroy

回答

1

錯誤消息本身告訴你什麼是錯的。 getRGB方法需要第5個參數中的一整數(int[]),並且您必須提供一個普通的int,儘管從代碼result [x][y].pixels中不清楚。

1
img.getRGB(x * sw, y * sh, sw, sh, result [x][y].pixels, 0, sh); 

結果的誤差[X] [Y] .pixels:--->這是一個值不陣列,該方法在這個地方採取在其中數據將被寫成這樣的陣列例如:

int[] outPixels = new int[width*height]; 
img.getRGB(0, 0, width, height, outPixels, 0, width); 

方法:

getRGB(startX, startY, w, h, rgbArray, offset, scansize) 

參數:

startX - the starting X coordinate 
startY - the starting Y coordinate 
w - width of region h - height of region 
rgbArray - if not null, the rgb pixels are written here 
offset - offset into the rgbArray scansize - scanline stride for the rgbArray