I am new for java. I have 2D binary matrix with only 1s and 0s now. I want to save it as jpg image(black and white) with same width and height. How could I realize that? I t
JHeatChart
does this job as well without you having to create a custom image library.
http://www.javaheatmap.com/
// Create some dummy data.
double[][] data = new double[][]{{3,2,3,4,5,6},
{2,3,4,5,6,7},
{3,4,5,6,7,6},
{4,5,6,7,6,5}};
// Step 1: Create our heat map chart using our data.
HeatChart map = new HeatChart(data);
// Step 2: Customise the chart.
map.setTitle("This is my heat chart title");
map.setXAxisLabel("X Axis");
map.setYAxisLabel("Y Axis");
// Step 3: Output the chart to a file.
map.saveToFile(new File("java-heat-chart.png"));
What you are essentially trying to do is make a heat map. And instead of a range of values ranging from 0 to whatever, you have a range of 0 and 1.
Replace double[][] data = new double[][](//etc);
with your boolean array.