Most solar hard X-ray (HXR) imagers in the past and current solar missions obtain X-ray images via Fourier transform imaging technology, which requires proper imaging algorithms to reconstruct images from spatially-modulated or temporally-modulated signals. A variety of algorithms have been developed during the last 50 years for the characteristics of respective instruments. In this work, we present a new imaging algorithm developed based on deep learning for the Hard X-ray Imager (HXI) onboard the Advanced Space-based Solar Observatory (ASO-S) and the preliminary test results of the algorithm with both simulated data and observations. We first created a training dataset by obtaining modulation data from simulated HXR images of single, double and loop-shaped sources, respectively, and the patterns of HXI sub-collimators. Then, we introduced machine-learning algorithm to develop a pattern-based deep learning network model: HXI_DLA, which can directly produce an image from modulation counts. After training the model with simple sources, we tested DLA for simple sources, extended sources, and double sources for imaging dynamic range. Finally, we compared CLEAN and DLA images reconstructed from HXI observations of three flares. Overall, these imaging tests revealed that the current HXI_DLA method produces comparable image result to those from the widely used imaging method CLEAN. In some cases, DLA images are even slightly better. Besides, HXI_DLA is super fast for imaging and parameter-free. Although this is only the first step towards a fully developed and practical DLA method, the tests have shown the potential of deep learning in the field of solar hard X-ray imaging.