A method is described whereby a sequence of X-ray images at closely spaced photon energies is acquired using a scanning transmission X-ray microscope, and aligned. Near-edge absorption spectra can then be obtained both from large, irregular regions, and from regions as small as the spatial resolution of the microscope (about 40 nm in the examples shown here). The use of the technique is illustrated in examination of a layered polymer film, a micrometeorite section, and an interplanetary dust particle section.