Fixed bug that only appeared in errors.
Added a function to copy image data.