  The celebrated Heinz inequality asserts that $ 2|||A^{1/2}XB^{1/2}|||\leq
|||A^{\nu}XB^{1-\nu}+A^{1-\nu}XB^{\nu}|||\leq |||AX+XB|||$ for $X \in
\mathbb{B}(\mathscr{H})$, $A,B\in \+$, every unitarily invariant norm
$|||\cdot|||$ and $\nu \in [0,1]$. In this paper, we present several
improvement of the Heinz inequality by using the convexity of the function
$F(\nu)=|||A^{\nu}XB^{1-\nu}+A^{1-\nu}XB^{\nu}|||$, some integration techniques
and various refinements of the Hermite--Hadamard inequality. In the setting of
matrices we prove that \begin{eqnarray*}
&&\hspace{-0.5cm}\left|\left|\left|A^{\frac{\alpha+\beta}{2}}XB^{1-\frac{\alpha+\beta}{2}}+A^{1-\frac{\alpha+\beta}{2}}XB^{\frac{\alpha+\beta}{2}}\right|\right|\right|\leq\frac{1}{|\beta-\alpha|}
\left|\left|\left|\int_{\alpha}^{\beta}\left(A^{\nu}XB^{1-\nu}+A^{1-\nu}XB^{\nu}\right)d\nu\right|\right|\right|\nonumber\\
&&\qquad\qquad\leq
\frac{1}{2}\left|\left|\left|A^{\alpha}XB^{1-\alpha}+A^{1-\alpha}XB^{\alpha}+A^{\beta}XB^{1-\beta}+A^{1-\beta}XB^{\beta}\right|\right|\right|\,,
\end{eqnarray*} for real numbers $\alpha, \beta$.
