1. An image forming apparatus comprising: a light-emitting unit configured to emit light toward an image carrier or a recording medium; a first light-receiving unit that includes a plurality of first light-receiving elements arranged along a first direction that is a movement direction of the image carrier or the recording medium, and is arranged so as to receive light emitted from the light-emitting unit and specularly reflected off the image carrier or the recording medium; a second light-receiving unit arranged at a different position from the first light-receiving unit in a second direction different from the first direction, and that includes a plurality of second light-receiving elements arranged along the first direction, the second light-receiving unit being arranged so as to receive light emitted from the light-emitting unit and reflected off the image carrier or the recording medium; a selection unit configured to select a first mode or a second mode, in the first mode, a first light-receiving element among the plurality of first light-receiving elements being set as a first effective light-receiving element and a second light-receiving element among the plurality of second light-receiving elements being set as a second effective light-receiving element, and in the second mode, a first light-receiving element among the plurality of first light-receiving elements or a second light-receiving element among the plurality of second light-receiving elements being set as a third effective light-receiving element; a generation unit configured to generate, if the first mode is selected by the selection unit, a first detection signal from an output of the first effective light-receiving element and a second detection signal from an output of the second effective light-receiving element, and to generate, if the second mode is selected by the selection unit, a third detection signal from an output of the third effective light-receiving element; and a detection unit configured to detect i) a target formed on the image carrier or the recording medium or ii) a surface of the image carrier or the recording medium, based on the first detection signal and the second detection signal or based on the third detection signal.