Digital cameras work by detecting light intensity and frequency over a 2D grid. A lens focuses light from a single point, which creates an inverted image when these values are registered on the sensor grid. The image captured is then re-inverted to correct for this when converted to pixels on a screen. You now have a digital photograph. This is the pinhole camera model, and it forms the basic theory for of nearly all modern photography and computer vision applications.
Modern cameras lenses can have their focal length changed to create a clear image for objects at different distances.