2
我在NetBeans平臺上製作應用程序。我想繪製他的程序。我有紅色,綠色和藍色的圖像像素。所以,請任何人向我訴說,我如何繪製直方圖使用這個像素值?我的代碼在下面,其中我採取圖像的紅色,綠色和藍色像素值。如何繪製使用RGB像素值的直方圖?
enter code here
import java.awt.Component;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class WalkImageTest10 extends Component {
public static void main(String[] foo) throws IOException {
WalkImageTest10 wa= new WalkImageTest10();
}
public void printPixelARGB(int pixel) {
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel) & 0xff;
System.out.println("argb: " + alpha + ", " + red + ", " + green + ", " + blue);
//System.out.println(pixel);
}
private void marchThroughImage(BufferedImage image) {
int w = image.getWidth();
int h = image.getHeight();
int pixel;
System.out.println("width, height: " + w + ", " + h);
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
//System.out.println("x,y: " + j + ", " + i);
pixel = image.getRGB(j, i);
printPixelARGB(pixel);
//System.out.println("value of K:"+k+ " value of pixel: " + pixel[j][i]);
}
}
System.out.println("loop is completed");
}
public WalkImageTest10() throws IOException {
// this is an image of a white spot on a black background.
// with the smoothing in the image it's of course not all black
// and white
BufferedImage image =
ImageIO.read(new File("F:\\java\\aimages\\003.jpg"));
marchThroughImage(image);
}
}
即使糾正你的拼寫錯誤後,我不能完全明白你的問題。 「我已經有紅色,綠色和藍色的圖像像素」是什麼意思? – 2012-04-10 14:19:44
sir/mem,我想說我從圖像中獲取像素值,然後我想使用像素值繪製該圖像的直方圖,那麼如何繪製直方圖? – Jay 2012-04-10 14:22:51
您是否想要繪製直方圖來顯示圖像中紅色,藍色和綠色像素的數量? – 2012-04-10 15:21:08