An X-ray detector comprises a directly converting semiconductor layer having a plurality of pixels for converting incident radiation into electrical measurement signals with a band gap energy characteristic of the semiconductor layer, wherein said incident radiation is x-ray radiation emitted by an x-ray source or light omitted by at least one light source. An evaluation unit calculates evaluation signals per pixel or group of pixels from first electrical measurement signals generated when light from said at least one light source at a first intensity is coupled into the semiconductor layer, and second electrical measurement signals generated when light from said at least one light source at a second intensity is coupled into the semiconductor layer. A detection unit determines detection signals from electrical measurement signals generated when x-ray radiation is incident onto the semiconductor layer, and a calibration unit calibrates the detection unit on the basis of the evaluation signals.