A novel image encryption algorithm based on deep neural network (DNN) is proposed. First, a new encryption unit with the deep neural network (EDNN) is designed. The EDNN is a multilayer forward neural network, and the weight matrices of the EDNN are composed of some scrambled discrete cosine transform (DCT) coefficients matrices to encrypt directly the original image. Then, the original image can be recovered by a decryption unit with the deep neural network (DDNN). For the DDNN, its network structure is symmetric with the EDNN, and the original image can be recovered with two pursuit algorithms corresponding to two activation functions of the EDNN, respectively. The experimental results show the effectiveness of the EDNN for image encryption, and demonstrate that the proposed method can effectively resist brute force attack, statistical attack, differential attack and cutting attack.