High-pressure diamond anvil cells have been widely used to create novel states of matter. Nevertheless, the lack of universal in-situ magnetic measurement techniques at megabar pressures makes it difficult to understand the underlying physics of materials’ behavior at extreme conditions, such as high-temperature superconductivity of hydrides and the formation or destruction of the local magnetic moments in magnetic systems. Here, we break through the limitations of pressure on quantum sensors by modulating the uniaxial stress along the nitrogen-vacancy axis and develop the in-situ magnetic detection technique at megabar pressures with high sensitivity (~1μT/Hz\\documentclass[12pt]{minimal} \\usepackage{amsmath} \\usepackage{wasysym} \\usepackage{amsfonts} \\usepackage{amssymb} \\usepackage{amsbsy} \\usepackage{mathrsfs} \\usepackage{upgreek} \\setlength{\\oddsidemargin}{-69pt} \\begin{document}$$\\sim 1{{{\\rm{\\mu }}}}{{{\\rm{T}}}}/\\sqrt{{{{\\rm{Hz}}}}}$$\\end{document}) and sub-microscale spatial resolution. By directly imaging the magnetic field and the evolution of magnetic domains, we observe the macroscopic magnetic transition of Fe3O4 in the megabar pressure range from ferrimagnetic (α-Fe3O4) to weak ferromagnetic (β-Fe3O4) and finally to paramagnetic (γ-Fe3O4). The scenarios for magnetic changes in Fe3O4 characterized here shed light on the direct magnetic microstructure observation in bulk materials at high pressure and contribute to understanding magnetism evolution in the presence of numerous complex factors such as spin crossover, altered magnetic interactions and structural phase transitions.