Workaround:
1. Read the picture data, and then call the method in 2 to verify
NSData* data = [NSData dataWithContentsOfFile:imagePath];
2. Determine if a valid PNG image, JPG, use the UIImageJPEGRepresentation method
/** * Verify that the picture is a valid PNG image * * @param imageData image file directly get the NSData object * * @return is a valid PNG picture */- (BOOL) Isvalidpngbyimagedata: (NSData*) imagedata{UIImage* image = [UIImageImagewithdata:imagedata];///First case: by [UIImage imagewithdata:data]; If image is nil, then ImageData must be invalid if(Image = =Nil&& ImageData! =Nil) {return NO; }///second situation: The picture is OK, but part of it is broken, it will pass the first step verification, then the following method is necessary. Convert the image to PNG data, if the PNG data can be generated correctly, then this picture is complete OK, if not, then the picture is damaged NSData* TempData = uiimagepngrepresentation (image);if(TempData = =Nil) {return NO; }Else{return YES; }}
iOS error: <error>: imageio:png idat:invalid stored block lengths