Can you describe a little more about the problem:
How are you manipulating the image? Just the image data or the header too? What do you mean by "mismatch"? Is the image different to what you expect, or just the metadata? What fields of metadata are different to what you expect, and how?