A maskless lithography method to realize the rapid and cost-effective fabrication of micro-optics elements with arbitrary surface profiles is reported. A digital micro-mirror device (DMD) is applied to flexibly modulate that the exposure dose according to the surface profile of the structure to be fabricated. Due to the fact that not only the relationship between the grayscale levels of the DMD and the exposure dose on the surface of the photoresist, but also the dependence of the exposure depth on the exposure dose, deviate from a linear relationship arising from the DMD and photoresist, respectively, and cannot be systemically eliminated, complicated fabrication art and large fabrication error will results. A method of compensating the two nonlinear effects is proposed that can be used to accurately design the digital grayscale mask and ensure a precise control of the surface profile of the structure to be fabricated. To testify to the reliability of this approach, several typical array elements with a spherical surface, aspherical surface, and conic surface have been fabricated and tested. The root-mean-square (RMS) between the test and design value of the surface height is about 0.1 μm. The proposed method of compensating the nonlinear effect in maskless lithography can be directly used to control the grayscale levels of the DMD for fabricating the structure with an arbitrary surface profile.