Optimized drawimage function for faster drawing