It's natural to associate the X-rays from cosmic objects with an X-ray from the doctor's office, but the comparison is a bit tricky. A doctor's X-ray machine consists of two parts: an X-ray source at one end, and a camera at the other. The arm or mouth or other body part to be examined is placed in between these two parts. X-rays from the source shine through the body part, and the camera records the X-rays that reach the photographic film. Bone is denser than muscle tissue and skin, so it stops more of the X-rays. Fewer X-rays make it to the region of the film that's behind the bone, creating an X-ray shadow image. In the developed film negative, the shadow image of the bone looks lighter than the rest of the picture, since that part of the film was exposed to few if any X-rays.
There's much more space between the two ends of the system that allows us to make images of the X-ray emissions from cosmic objects. The cosmic object (such as a galaxy, or matter near a black hole) acts like the source in the doctor's machine, emitting X-rays on its own. On the other end, Chandra collects and records the X-rays shining into it -- like the camera on the X-ray machine. A Chandra X-ray image of, say, a galaxy gives an idea of how the galaxy is emitting X-rays, just like a photograph of the galaxy at visible wavelengths gives an idea of how the galaxy is emitting visible light.
Could we photograph the source on an X-ray machine by simply eliminating the patient? It turns out the X-ray source is too close to the camera -- it illuminates the whole surface of the film uniformly, without any detail. (This is a good thing for the X-ray image -- it provides a smooth backdrop for the broken arm.)
So an X-ray machine can't act like Chandra and photograph an X-ray source. Chandra, however, can act like an X-ray machine and reveal information about what's between the source and the camera. Space is not empty, and there's bound to be material between us and a distant X-ray source -- perhaps a vast cloud of gas, or a disk of matter around a black hole. Instead of blocking all the X-rays (like bones in a medical X-ray) these intervening objects usually absorb only particular wavelengths of X-ray radiation. By separating the X-ray light from the source into its component wavelengths and examining these absorption bands, we can learn about the matter between us and the X-ray source.
In very rare instances, an object such as a planet or satellite of a planet will move in front of, or transit an extended cosmic X-ray source, such as the Crab Nebula. Under these circumstances, an X-ray shadow of the planet or satellite can be imaged by Chandra. This happened in January of 2003 when Titan - Saturn's largest moon and the only moon in the Solar System with a thick atmosphere - passed directly in front of the Crab Nebula. By using Chandra to capture an image of the X-ray shadow cast by Titan, astronomers were able to make the first X-ray measurement of the extent of its atmosphere.