2012-01-21 56 views
3

我可以使用以下函數獲取r,g,b值。如何從Java中的R,G,B值獲取rgb像素值BufferedImage

int rgb=bImg.getRGB(i, j); 
int r=(rgb>>16) & 0xff; 
int g=(rgb>>8) & 0xff; 
int b=(rgb) & 0xff; 

現在我做的這些值某些操作需要使用下面的函數

bImg.setRgb(int x,int y,int rgb) 

設置RGB值,但我不知道如何從R,G,B值計算RGB 。

回答

3
int rgb = (r<<16) + (g<<8) + b; 

或者

int rgb = (r<<16) | (g<<8) | b; 

會做相反的操作和rgb存儲到一個整數,你已經破譯。

相關問題