generalize drawPhotoToBitmapData function