1. An electronic camera comprising: an image sensor having an image pickup plane on an image plane of an optical system; a formation changing section changing an image size of the optical system on the image pickup plane; and a control section driving and controlling the image sensor and the formation changing section wherein: the control section drives the formation changing section to set a plurality of states of the image size of the optical system and drives the image sensor to obtain a plurality of images in each of the states, the plurality of states being different from each other; and the control section compares the plurality of images to find a part of the image which has not varied in size in accordance with a change in the image size, and determines the found part as image of a foreign material attached to some place in an imaging light path of the electronic camera.