Check that image pixel is in the image before writing it.