Only set background image if background is visible

This helps to remove flickering when setting the image before it is
visible