A new software program was developed for tracing electron trajectories in electrostatic and magnetic fields with a high precision. This source program based on a boundary element method (BEM) has been applied to evaluate the brightness of a magnetic field immersion-type field emission gun. The charge distribution on the electrode surface obtained by the BEM was used in a three-dimensional electromagnetic field analysis to calculate electron trajectories in a field emission with a sufficiently high precision. The brightness of this electron gun was evaluated as a function of emission half-angle by ray tracing electron trajectories in electrostatic and magnetic fields. The obtained results indicate that the brightness of the magnetic field immersion-type field emission gun is very high compared with that of a conventional field emission gun equipped with a Butler-type electrostatic lens even slightly better than that of a field emission gun equipped with a preaccelerating magnetic lens which has been used in a 1 MV electron microscope.