1. A method for generating a gain of an image frame comprising: setting the gain of the image frame to 1; scanning images of a plurality of beginning dummy rows of the image frame; averaging the images of the plurality of the beginning dummy rows of the image frame to generate an average value of the images of the plurality of the beginning dummy rows of the image frame; generating a corresponding gain according to the average value of the images of the plurality of the beginning dummy rows of the image frame; and generating an image of remaining rows of the image frame according to information of the remaining rows of the image frame and the corresponding gain.