1. A non-transitory machine readable medium of a device that captures images, the medium storing a program that when executed by at least one processing unit generates a high dynamic range (HDR) image of a scene, the program comprising sets of instructions for: capturing a plurality of images of the scene at different exposure levels, wherein the different exposure levels are selected based at least in part upon detected lighting conditions within the scene, including: capturing and storing, prior to receiving a command to generate the HDR image of the scene, at least one image at a first exposure level; detecting the lighting conditions within the scene based on an analysis of at least one of the at least one image captured and stored; and capturing, upon receiving the command to generate the HDR image of the scene, at least a first image at a second exposure level selected based at least in part upon the detected lighting conditions within the scene; and compositing the plurality of images to generate the HDR image of the scene.