A device for detecting X-rays radiated out of a substrate surface, said device comprising at least one X-ray detector, a resolver grating and a modulator grating, said resolver grating with at least one opening facing towards said X-ray detector is arranged in front of said X-ray detector. Said modulator grating is provided between said resolver grating and said substrate at a predetermined distance from said resolver grating and said substrate, where said modulator grating having a plurality of openings in at least a first direction, wherein said x-rays from said surface is spatially modulated with said modulator grating and resolver grating.