A method of an electronic device which comprises a display (160, 260), a camera module including an image sensor and a processor that controls the image sensor, wherein the image sensor includes a plurality of unit pixels, and each of the plurality of unit pixels includes at least two subpixels, the method comprising: identifying, by the processor, one pre-set mode amongst a first, second, third and fourth mode for generating an image corresponding to an object by using an optical signal; determining a setting of at least one image attribute among a resolution, a frame rate and/or an autofocus, "AF," speed to be used for generating the image at least based on the mode; when the mode is identified as the third mode: acquiring, for each unit pixel, at least two signals corresponding to the at least two subpixels from the image sensor; obtaining information for calculating at least one phase difference between two of the at least two subpixels based on the acquired at least two signals; generating image data for each unit pixel by combining or averaging the at least two signals; and outputting the image data for the plurality of unit pixels through an interface to the display and outputting the information for calculating the at least one phase difference for the plurality of unit pixels; when the mode is identified as the fourth mode; dividing the plurality of pixels into a group of first unit pixels and a group of second unit pixels; selectively combining the signals of respective subpixels within each first unit pixel to generate unit pixel image data and outputting the signals of respective subpixels within each second unit pixel; obtaining the information for calculating at least one phase difference between two of the at least two subpixels within each second unit pixel using the signals of respective subpixels; generating unit pixel image data by combining the signals of respective subpixels within each second unit pixel; generating image data by gathering unit pixel image data generated for each of the first and second unit pixels; and outputting the generated image data for the plurality of unit pixels through the interface to the display and outputting the information for calculating the phase difference for the plurality of unit pixels; the method further comprising: displaying an image generated based on the generated image data for the plurality of unit pixels outputted according to the identified mode. identifying, by the processor, one pre-set mode amongst a first, second, third and fourth mode for generating an image corresponding to an object by using an optical signal; determining a setting of at least one image attribute among a resolution, a frame rate and/or an autofocus, "AF," speed to be used for generating the image at least based on the mode; when the mode is identified as the third mode: acquiring, for each unit pixel, at least two signals corresponding to the at least two subpixels from the image sensor; obtaining information for calculating at least one phase difference between two of the at least two subpixels based on the acquired at least two signals; generating image data for each unit pixel by combining or averaging the at least two signals; and outputting the image data for the plurality of unit pixels through an interface to the display and outputting the information for calculating the at least one phase difference for the plurality of unit pixels; when the mode is identified as the fourth mode; dividing the plurality of pixels into a group of first unit pixels and a group of second unit pixels; selectively combining the signals of respective subpixels within each first unit pixel to generate unit pixel image data and outputting the signals of respective subpixels within each second unit pixel; obtaining the information for calculating at least one phase difference between two of the at least two subpixels within each second unit pixel using the signals of respective subpixels; generating unit pixel image data by combining the signals of respective subpixels within each second unit pixel; generating image data by gathering unit pixel image data generated for each of the first and second unit pixels; and outputting the generated image data for the plurality of unit pixels through the interface to the display and outputting the information for calculating the phase difference for the plurality of unit pixels; dividing the plurality of pixels into a group of first unit pixels and a group of second unit pixels; selectively combining the signals of respective subpixels within each first unit pixel to generate unit pixel image data and outputting the signals of respective subpixels within each second unit pixel; obtaining the information for calculating at least one phase difference between two of the at least two subpixels within each second unit pixel using the signals of respective subpixels; generating unit pixel image data by combining the signals of respective subpixels within each second unit pixel; generating image data by gathering unit pixel image data generated for each of the first and second unit pixels; and outputting the generated image data for the plurality of unit pixels through the interface to the display and outputting the information for calculating the phase difference for the plurality of unit pixels; the method further comprising: displaying an image generated based on the generated image data for the plurality of unit pixels outputted according to the identified mode.