Do a better job at copying image data
(cherry picked from commit 6716d8395485439bbc60acb558fa1bb180575c81)