我只是想將此彩色圖像轉換爲黑白圖像,但我不知道如何做到這一點。我只知道如何獲得像素。你可以幫我嗎?如何在Java中將圖像從顏色轉換爲黑白(灰度)
private BufferedImage image;
private int[][]rgbValue;
public void setRgbValue(BufferedImage image){
int width = image.getWidth();
int height = image.getHeight();
rgbValue = new int[width*height][3];
int counter = 0;
for(int i=0 ; i<width ; i++){
for(int j=0 ; j<height ; j++){
int color = image.getRGB(i, j);
int red = (color & 0x00ff0000) >> 16;
int green = (color & 0x0000ff00) >> 8;
int blue = (color & 0x000000ff);
rgbValue[counter][0] = red;
rgbValue[counter][1] = green;
rgbValue[counter][2] = blue;
counter++;
}
}
}
如何將此代碼與此代碼結合使用?
temp = red;
red = green;
green = blue;
blue = temp;
temp = 0;
rgb[i] = ((red << 16)) + ((green << 8)) + (blue);
if(rgb[i] <= 0x670000){
rgb[i] = 0x000000;
} else {
rgb[i] = 0xffffff;
}
OP沒有提到的JavaScript /輸出到網頁瀏覽器 – 2012-02-29 16:40:21