2014-07-11 44 views
0

我的形象已經輸出三個通道,但根據顏色用java結合RGB通道和輸出通道

public class RGB { 
    public static int getR(int pixel) { 
     return(pixel >> 16 & 0xff); 
    } 

    public static int getG(int pixel) { 
     return (pixel >> 8 & 0xff); 
    } 

    public static int getB(int pixel) { 
     return (pixel & 0xff); 
    } 

    public static int combine(int r, int g, int b) { 
     int rgb = (r << 16) | (g << 8) | b; 
     return rgb; 
    } 
} 

難道我錯移,似乎錯了嗎?我能做什麼?

回答

0

使用java.awt.Color中的類作爲一個參考,他們改變了幾件事情:

public int getRed(int pixel) { 
    return (pixel >> 16) & 0xFF; 
} 

public int getGreen(int pixel) { 
    return (pixel >> 8) & 0xFF; 
} 

public int getBlue(int pixel) { 
    return (pixel >> 0) & 0xFF; 
} 

public static combine(int r, int g, int b) { 
    return combine(r, g, b, 255); 
} 

public static combine(int r, int g, int b, int a) { 
    return ((a & 0xFF) << 24) | 
      ((r & 0xFF) << 16) | 
      ((g & 0xFF) << 8) | 
      ((b & 0xFF) << 0); 
} 

我根據,結合了他們的構造函數。它有很大的不同,並且他們在不同的地方爲他們的獲得者提供了括號。