Why is Texture.EncodeToPNG() flipping my image and messing up the read origin?

The image I get from texture.GetRawTextureData() is correct. This forum won’t let me upload it but it is perfect. However when I use texture.EncodeToPNG() I get this upsidedown chopped up junk. Am I missing a simple setting, or offset somewhere??

Okay I got it!! I was encoding a GeoTiff file which comes with a header containing geospatial data. When i did texture.GetRawBytes() it would display the header bytes as just regular pixel data and write the image correctly. However, the texture.EncodeToPNG() started where the header left off which gave me the weird offset. Not only does the PNG encoding do this but also the texture sampler in my shader. Lesson learned is that you MUST handle the header before you sample the texture.