Abstract The metal halide perovskites exhibit excellent performance as the direct X-ray detectors owing to their strong absorption capability, long carrier lifetime and diffusion length, radiation ruggedness, etc. For imaging applications, the ionic migration of perovskites and charge sharing effect between the adjacent pixels have a significantly negative impact on the spatial resolution. Herein, for the first time, the porous anodic aluminum oxides (AAO) have been used as a template to grow the CsPbBr2I thick film for the direct X-ray detection. Benefiting from the oxygen passivation effect, the activation energy for ionic migration has been observed to increase to 0.701 eV, whereas the dark current drift (1.01 × 10−5 nA cm−1s−1V−1) is one to two orders of magnitude lower than the other lead halide perovskite single crystals and films. Moreover, the AAO insulating wall effectively blocks the charge diffusion effect across a pixel pitch of 10 μm. Overall, the findings reported in this study open a new route for reducing the ionic migration and pixel crosstalk, thus, bringing the perovskite X-ray detectors close to the practical applications.