In an X-ray tube, electrons are accelerated through a large p.d. and hit a metal target. As they are stopped, part of their kinetic energy is given out as X-ray photons. An electron that gives all its energy to one photon produces the photon of greatest energy, so the spectrum has a minimum wavelength.
X-rays are absorbed more by some materials than by others. Bone absorbs much more than soft tissue, so it leaves a clear shadow on the detector. Contrast is the difference in blackening between different areas of the image.
A CT scan takes many X-ray images of one section from different angles and combines them into a 2D image. Repeating this along the body and combining the sections gives a 3D image.