Refactoring of function genBitmapImage