【发布时间】:2012-04-22 20:13:46
【问题描述】:
我在 netbeans 平台上制作应用程序。我想画直方图。我有红色、绿色和蓝色的图像像素。所以,请任何人向我建议我如何使用这个像素值绘制直方图?我的代码在下面,我在其中获取图像的红色、绿色和蓝色像素值。
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);
}
}
【问题讨论】:
-
即使纠正了您的拼写错误,我也无法完全理解您的问题。 “我已经有了红色、绿色和蓝色的图像像素”是什么意思?
-
先生/mem,我想说我从图像中获取像素值,然后我想使用像素值绘制该图像的直方图,那么我该如何绘制直方图?
-
您是否要绘制一个直方图来显示图像中红色、蓝色和绿色像素的数量?
-
我使用上面的代码得到红色、绿色