We demonstrate that images of flux vortices in a superconductor taken with a transmission electron microscope can be used to measure the penetration depth and coherence length in all directions at the same temperature and magnetic field. This is particularly useful for MgB2, where these quantities vary with the applied magnetic field and values are difficult to obtain at low field or in the c direction. We obtained images of flux vortices from a MgB2 single crystal cut in the ac plane by focused ion beam milling and tilted to 45 degrees. with respect to the electron beam about the crystallographic a axis. A new method was developed to simulate these images that accounted for vortices with a nonzero core in a thin, anisotropic superconductor and a simplex algorithm was used to make a quantitative comparison between the images and simulations to measure the penetration depths and coherence lengths. This gave penetration depths Lambda(ab) = 100 +/- 35 nm and Lambda(c) = 120 +/- 15 nm at 10.8 K in a field of 4.8 mT. The large error in Lambda(ab) is a consequence of tilting the sample about a and had it been tilted about c, the errors on Lambda(ab) and Lambda(c) would be reversed. Thus obtaining the most precise values requires taking images of the flux lattice with the sample tilted in more than one direction. In a previous paper [J. C. Loudon et al., Phys. Rev. B 87, 144515 (2013)], we obtained a more precise value for Lambda(ab) using a sample cut in the ab plane. Using this value gives Lambda(ab) = 107 +/- 8 nm, Lambda(c) = 120 +/- 15 nm, xi(ab) = 39 +/- 11 nm, and xi(c) = 35 +/- 10 nm, which agree well with measurements made using other techniques. The experiment required two days to conduct and does not require large-scale facilities. It was performed on a very small sample, 30 x 15 mu m and 200-nm thick, so this method could prove useful for superconductors where only small single crystals are available, as is the case for some iron-based superconductors.