我只是想把这个彩色图像转换为黑白,但我不知道该怎么做.我只知道如何获得像素.你能帮助我吗?
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++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何将其与此代码结合使用?
temp …Run Code Online (Sandbox Code Playgroud)