We propose a new autofocus method for digital cameras based on the separation of color components from the incoming light rays and the measure of their disparity. For separating color components, we place two apertures with the red and blue color filters on them. This enables us to get two monochromatic images that have disparities proportional to the distances of the objects from the camera. We also propose a new measure to find the disparity of these color components because the conventional disparity measures show low accuracy for the pair of different color channel images. The measure is based on the observation that the overlap of images with disparity has many weak gradients, whereas the overlap with no disparity has a small number of strong gradients. One of two images is shifted from left to right, and the measure is computed for each position. Then, the position with the maximum measure is considered as the disparity, and the direction and distance of focus are computed from the estimated disparity and camera parameters. The proposed method is implemented in a commercial compact camera, and it has been demonstrated that the method finds the focus in a wide range of distance and illumination conditions.