We present a method that can automatically determine the optimal camera exposure time for high-quality deformation measurement with digital image correlation (DIC) techniques. The proposed method requires to capture a series of surface images of a test sample at its reference state with different camera exposure times. The relationship between the mean intensity gradients (MIG) and average grayscales of these images reveals that the best speckle pattern quality of a speckled sample surface always corresponds to an optimal average grayscale. Thus, the proposed method can serve for two purposes in DIC practice. First, at the initial state, the camera exposure time can be adjusted automatically to obtain a reference image with best quality. Second, by adjusting the camera exposure time to make the average grayscale of an image close to the predetermined optimal value, the proposed method can adaptively output high-quality deformed images with almost constant speckle pattern quality regardless of serious ambient light variations. Experimental results demonstrated the proposed method can automatically obtain stable and high-quality speckle pattern images and thus better DIC measurement compared with regular DIC techniques using a fixed camera exposure time. The proposed method shows great potential in high-temperature DIC applications.