iOS UIImageJPEGRepresentation error: Not a JPEG file: starts with 0xff 0xd9

后端 未结 1 1941
一个人的身影
一个人的身影 2020-12-10 04:47

I am writing a .jpg file to my app\'s Documents directory like this:

NSData *img = UIImageJPEGRepresentation(myUIImage, 1.0);
BOOL retValue = [img writeToFil         


        
相关标签:
1条回答
  • 2020-12-10 05:06

    The images were not corrupt, I was able to display them correctly. The issue is possibly a bug in UIImage, or perhaps the documentation should be more clear about using imageWithContentsOfFile:.

    I was able to eliminate the error message by changing

    UIImage *myImage = [UIImage imageWithContentsOfFile:path];
    

    to

    NSData *img = [NSData dataWithContentsOfFile:path];
    UIImage *photo = [UIImage imageWithData:img];
    
    0 讨论(0)
提交回复
热议问题