Fix ImageWrite bit bug, remove test code