A method is disclosed for generating at least one x-ray image of a patient having incorporated contrast medium, using x-rays having an energy spectrum and an x-ray detector. The energy spectrum is modified by at least one first filter arranged in the beam path in front of the patient, the patient absorbing a dose in order to generate detector data for the x-ray image and the x-ray image having a CNR value which represents the ratio of the maximum contrast in the image to the noise. The energy spectrum and contrast medium are matched to each other, taking into account the thickness of the patient to be x-rayed, in such a way that an optimization criterion which is taken from an x-ray image that is generated or simulated by way of trials is maximized. Furthermore, an x-ray system is also disclosed.