iOS UIImageJPEGRepresentation error: Not a JPEG file: starts with 0xff 0xd9
I am writing a .jpg file to my app's Documents directory like this: NSData *img = UIImageJPEGRepresentation(myUIImage, 1.0); BOOL retValue = [img writeToFile:myFilePath atomically:YES]; Later, I load that image back into a UIImage using: UIImage *myImage = [UIImage imageWithContentsOfFile:path]; I know it works because I can draw the image in a table cell and it is fine. Now if I try to use UIImageJPEGRepresentation(myImage, 1.0), the debugger prints out these lines: <Error>: Not a JPEG file: starts with 0xff 0xd9 <Error>: Application transferred too few scanlines And the function returns nil.