I am working on a project and I would like to display a single line histogram that looks like a bar graph except each line in the bar graph represents a pixel and its greyscale value.
I have a array full of greyscale values, I just need to put them into this histogram and have it display the lines which will represent the values.. sort of like this
IMAGE [minimize][maximize][close]
picture histogram
I
(Loaded Picture) I I
I I I
I I I I
[open][save]
And below is the code loading the array... I just need to get some code that will use those greyscale values and represent them as bars like above.
public void showImage(File fileName) {
Scanner scan;
try {
scan = new Scanner(fileName);
typefile = scan.next();
iname = scan.next();
width = scan.nextInt();
height = scan.nextInt();
maxshade = scan.nextInt();
array = new int[width][height];
for(int r = 0; r < array.length; r++){
for(int c = 0; c < array[r].length; c++){
array[r][c] = scan.nextInt();
imageArray = array;
repaint();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
I know I have to do something like...
int hist[] = new int[256];
for (int r = 0; r < array.length; r++)
for (int c = 0; c < array[r].length; c++)
hist[array[r][c]]++;
But I don't know where to go from there or how to draw my graph.
See Question&Answers more detail:os