Updated WriteImg.c, fixed bugs and errors.