I would recommend against writing multiple images to the same file. Instead, create multiple files with one image per file.

To read/write images, see this post: Images (read/write and drawing)