Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8753251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:23:29+00:00 2026-06-13T13:23:29+00:00

I am downloading multiple images from below code and saving to the DB. But

  • 0

I am downloading multiple images from below code and saving to the DB. But for some images I am getting below error.

Error: ImageIO: PNG invalid distance too far back
Error: ImageIO: PNG incorrect data check

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);                               
dispatch_async(queue, ^{
    NSString *imgStr = [dict  objectForKey:@"image"];                  
    imgStr = [imgStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imgStr]];
    UIImage *image = [UIImage imageWithData:imgData];

    dispatch_sync(dispatch_get_main_queue(), ^{
       mYImageView.image = image;
    });
});

enter image description here

How to check stored image is valid or not, so I can download image again?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:23:31+00:00Added an answer on June 13, 2026 at 1:23 pm

    For PNG images, check their first two bytes and last two bytes. Below is the method, hope it helps.

    Thanks. 🙂

    - (BOOL)isImageValid:(NSData *)data
    {
        BOOL val = YES;
    
        if ([data length] < 4) 
            val = NO;
    
        const char * bytes = (const char *)[data bytes];
    
        if (bytes[0] != 0x89 || bytes[1] != 0x50) 
            val = NO;
        if (bytes[[data length] - 2] != 0x60 || 
            bytes[[data length] - 1] != 0x82) 
            val = NO;
    
        return val;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am downloading files from my server, saving them to device, and displaying them
I am downloading some information from a JSON feed about countries, states and their
How can I download multiple links simultaneously? My script below works but only downloads
Anyone can help me on downloading multiple files from the server side through the
It has been surprisingly hard to find a code example of downloading multiple files
I got the following error message while downloading using multiple threads: There were not
In my application , on clicking button , downloading some content from web server
I'm downloading sets of images in separated threads and saving them to the SD
Can I ask a rookie Java question? I am downloading some files from the
I need to allow multiple downloading of small documents in Rails, preferably using Paperclip

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.