我的代码是对的吗? 我想使用JAI和Jfreechart获得RGB直方图。
1)从planarimage创建直方图对象 2)histogram.getBins()获取RGB值 3)在jfreechart
的条形图上绘制此值 希望你能帮助我! 谢谢:)PlanarImage.wrapRenderedImage(img);
ParameterBlock pb = new ParameterBlock();
int[] bins = { 256 };
double[] low = { 0.0D };
double[] high = { 256.0D };
pb.addSource(img);
pb.add(null);
pb.add(1);
pb.add(1);
pb.add(bins);
pb.add(low);
pb.add(high);
RenderedOp op = JAI.create("histogram", pb, null);
Histogram histogram = (Histogram) op.getProperty("histogram");
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
int[][] data = histogram.getBins();
for (int i = 1; i<data.length;i++){
dataset.setValue(data[0][i], "color", String.valueOf(data[1][i]) );
}
JFreeChart chart = ChartFactory.createBarChart("test",
"test", "test", dataset, PlotOrientation.VERTICAL,
false, true, false);
try {
ChartUtilities.saveChartAsJPEG(new File("C:\\chart.jpg"), chart, 500, 300);
} catch (IOException e) {
System.err.println("Problem occurred creating chart.");
}