The interaction of a high intensity laser and a solid target generates a large number of hot electrons. When these hot electrons are transported in the target material, x-rays are produced, including Kα line and bremsstrahlung emissions. The contrast of Kα line emission, i.e., the intensity of Kα line relative to the intensity of bremsstrahlung continua around the Kα line, depends on the anisotropy of the bremsstrahlung emission and is related to the energy and transportation of the hot electrons. In the past, some researchers used axial or annular magnetic fields to collimate hot electrons, but whether these magnetic fields can enhance the contrast of Kα emission has not been studied. In the present work, the effect of an axially uniform magnetic field or an annular magnetic field with a Gaussian distribution on the contrast of Cu Kα emission is investigated by Monte Carlo simulations. The simulation results and analysis show that the axially uniform magnetic field cannot strengthen the anisotropy of the bremsstrahlung emission, so it cannot enhance the contrast of Kα emission efficiently. For the annular magnetic field with a Gaussian distribution, when an electron beam with a Boltzmann energy distribution is incident, due to the weak anisotropy of bremsstrahlung emission by low-energy electrons in the electron beam, the increase of Kα emission contrast is small. When an electron beam with a Boltzmann energy distribution, in which the low-energy part is cut off, or a mono-energetic electron beam is incident, the annular magnetic field with a Gaussian distribution significantly enhances the contrast of Kα emission in the back direction of the electron beam incidence. For an incident electron beam with an energy in the range of 200-1000 keV, an annular magnetic field with a Gaussian distribution and a peak value of approximately 100 T is optimal for enhancing the contrast of Kα emission. In consideration of existed experiments of producing annular magnetic fields and non-Boltzmann energy distribution hot electrons, it will be possible to generate higher contrast Kα emissions enhanced by magnetic fields in future experiments.