The existing encryption algorithms that generate visually meaningful images usually focus on the recovery of secret information, while neglecting the visual quality degradation of the carrier image, thereby increasing the possibility of being intercepted. This paper proposes a visually meaningful image encryption algorithm based on the attention mechanism and artificial bee colony optimization. It combines the attention mechanism in deep learning and the artificial bee colony optimization in optimization algorithms, aiming to maximize the visual effect of visually meaningful images. Firstly, the plaintext image is compressed and scrambled to obtain the secret information. Then the attention mechanism algorithm is applied to divide the cover image into visually salient regions, and the non-salient regions blocks are prioritized for embedding the secret information. By introducing the artificial bee colony optimization algorithm, the optimal values of noise visibility function (NVF), information entropy, and contrast weight are iteratively obtained. On this basis, select the positions and order of the sub-blocks to be embedded and perform IWT and LSB embedding to obtain the visually meaningful cipher images. Experimental results demonstrate that the proposed scheme effectively improves the quality of visually meaningful images.