IOS Error :( Error): ImageIO: png idat: invalid stored block lengths

Source: Internet
Author: User

IOS Error :( Error): ImageIO: png idat: invalid stored block lengths

Solution:

 

1. Read the image data and call the method in step 2 for verification.

NSData * data = [NSData dataWithContentsOfFile: imagePath];

2. Determine whether a PNG image is valid. For JPG images, use the UIImageJPEGRepresentation method.

/*** Verify whether the image is a valid PNG Image ** @ param imageData the NSData object obtained directly from the image file ** @ return whether it is a valid PNG Image */-(BOOL) isValidPNGByImageData :( NSData *) imageData {UIImage * image = [UIImage imageWithData: imageData]; // first case: When an image is directly generated through [UIImage imageWithData: data, if the image is nil, The imageData must be invalid if (image = nil & imageData! = Nil) {return NO;} // The second case: some of the images are OK, but some are broken. It will pass the first verification, you need to use the following method. Convert the image to PNG data. If the PNG data can be correctly generated, the image is complete and OK. If not, the image is damaged. NSData * tempData = UIImagePNGRepresentation (image ); if (tempData = nil) {return NO;} else {return YES ;}}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.