Gray-scale histogram is nearly trivial compared to color histogram (which is not trivial at all due to the fact that what to take for Luminosity is somewhat philosophical question, :-) for those who do not believe: see this:
http://en.wikipedia.org/wiki/HSL_color_space[
^]).
However, a even a gray-scale histogram is a bit less trivial then appears in the Answer by Albin. To start with, 255 is not a word constant like a speed of light. Usually, real bits per pixel vary from 8 to 16, but in practice a raw picture from a standard CMOS or CCD it's somewhere between 8 (8-bit mode) and 12 (16-bit mode). If remaining four bits are used in the output file really depends on in-camera processing: the dynamic range can be modified; the ultimate transformation use to use full range is called normalization.
As a result, the number of color bins can reach 2
12=4096 or 2
16=65536 which is bit to much to show directly. Number of bins should be arbitrarily selected based on the presentation and re-calculated into required number of bins grouping close colors together; the array should be of floating-point type and re-normalized to maintain consistent vertical scale.
Zinssame, please sort out your buttons and loading yourself and next time think of some better UI design (gosh, why everyone is asking about these buttons?). Access to the separate pixels fully depends on the library you want to use: System.Drawing or WPF (or anything else); you could have asked about the particular library you want to use. It is done in totally different ways. The techniques are well documented and sample codes are provided in MSDN, so it should not be a problem. You can ask a separate question if you face any problem.
—SA