Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

First load image I/O errors?

Hello all,
I'm trying to download images asynchronously then display them when downloaded. I'm using the same principles to do it as thisThis tutorial. The problem is that when I run the app for the first time all the images are either "pixel noise", the same image over and over, or partly loaded with some pixels in the image scrambled. I also get errors in the console like:

ImageIO: PNG Extra compressed data

ImageIO: PNG invalid block type

ImageIO: PNG invalid distance too far back

After the first time loading it all works fine with all the images rendering properly and no console errors. This happens whether I set the cache policy to not allow, allow, or anything in between.

This isn't a problem with the actual images. I have saved the PNG's as non-interlaced, re-saved the images to make sure nothing was wrong, and loaded a lot of different images from Google images. The problem remains.

And if I try changing the file to to JPG's the same problem occurs but the console just spits out different error messages.

Thanks for all the help!

PS. I'm using Xcode 4.3 and ARC.

-Shredder2794
Post edited by Shredder2794 on

Replies

  • FstuffFstuff Posts: 154Registered Users
    Shredder2794;428836 said:
    This isn't a problem with the actual images. I have saved the PNG's as non-interlaced, re-saved the images to make sure nothing was wrong, and loaded a lot of different images from Google images. The problem remains.
    Sounds like it's a problem with your code then!

    Seriously though, if you want people to help you debug your code, you'll need to show the code. Preferably reduced down to the bare minimum that can reproduce the bug. I would suggest you also break down your problem a little bit more. Analyze your async http request first, and then the UI component.
  • Shredder2794Shredder2794 Posts: 9New Users
    Fstuff;428841 said:
    Sounds like it's a problem with your code then!

    Seriously though, if you want people to help you debug your code, you'll need to show the code. Preferably reduced down to the bare minimum that can reproduce the bug. I would suggest you also break down your problem a little bit more. Analyze your async http request first, and then the UI component.
    Sorry for not including it at the beginning.
    The method loadImages is caleld when the view loads.

    -(void)loadImages{

    self.photosArray = [[NSMutableArray alloc] initWithObjects:
    @\"http://solar-center.stanford.edu/SID/images/earth.gif\",
    @\"http://freeimagesarchive.com/data/media/27/3_space.jpg\",
    @\"http://solar-center.stanford.edu/SID/images/earth.gif\",
    @\"http://freeimagesarchive.com/data/media/27/3_space.jpg\",
    @\"http://solar-center.stanford.edu/SID/images/earth.gif\",
    @\"http://freeimagesarchive.com/data/media/27/3_space.jpg\",
    @\"http://solar-center.stanford.edu/SID/images/earth.gif\",
    @\"http://freeimagesarchive.com/data/media/27/3_space.jpg\",
    nil];
    [self runTimerAndDownloadImages];
    }
    -(void)runTimerAndDownloadImages{

    for (int i = 0; i < [self.photosArray count]; i++) {

    NSURLRequest *request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:[self.photosArray objectAtIndex:i]] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0];
    NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
    if(connection){
    self.imageData = [NSMutableData data];
    }
    }
    }
    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    {
    [self.imageData setLength:0];
    }
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
    [self.imageData appendData:data];
    }

    - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    {
    NSLog(@\"Error!\");
    }

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {

    UIImage *downloadedImage = [[UIImage alloc] initWithData:self.imageData];

    [[self.buttonsArray objectAtIndex:self.downloadedImageNumber] setImage:downloadedImage forState:UIControlStateNormal];
    self.downloadedImageNumber++;
    }
  • FstuffFstuff Posts: 154Registered Users
    I don't see anywhere in your code where you tell the view that it needs to be refreshed. From the Apple View Programming Documentation Loading…
    View drawing occurs on an as-needed basis. . . When the actual content of your view changes, it is your responsibility to notify the system that your view needs to be redrawn. You do this by calling your view’s setNeedsDisplay or setNeedsDisplayInRect: method of the view. These methods let the system know that it should update the view during the next drawing cycle.
    This would explain why you are getting odd results the first time around, but then later (i.e. when the view is redrawn) everything looks fine.
Sign In or Register to comment.