views:

369

answers:

3
imgBiteSpot.clipsToBounds=YES; 
    NSData *imageData = [[[NSData alloc]init]autorelease];
    imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ObjBitSpot.StrImagePath]];
    if(imageData==0)
    {
     imgBiteSpot.image=[UIImage imageNamed:@"img-not-found.gif"];
    }
    else {
     UIImage *imgs = [[UIImage alloc] initWithData:imageData];
     UIGraphicsBeginImageContext(CGSizeMake(88,88));
     [imgs drawInRect:CGRectMake(0.0, 0.0, 88.0, 88.0)];
     UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
     UIGraphicsEndImageContext();
     imgBiteSpot.image=newImage;
     [imgs release];
    }


I have loaded an image to imgBiteSpot. The image is loaded from the webservice. The problem is that it takes too much time (35 seconds to 1 minute).

If I remove image -> code / load, the reaction time is just 0.2 seconds.

What is the solution to reduce the time for the image loading process?

Thanks in advance for your kind help.

+3  A: 

You're using NSData's method dataWithContentsOfURL:, which loads the data synchronously from the server, and thus blocks on the thread until the image is received.

What you should do instead is load a blank or "loading" image into your UIImage, then use NSURLConnection to download the image asynchronously and display it when it's done. See the NSURLConnection reference and the URL Loading System doc.

Tim
A: 

I found something different.

I have chosen something new.

For smaller view - I have stored smaller images on site - for smaller images like in table Cell View - I have stored huge images on site - for huge images like UIImageView

That makes may table load faster.

sugar
While this may produce performance speedups for you, I'm concerned you're missing the underlying issue - that you're using a synchronous, blocking method for an Internet connection that may be very unreliable. If an iPhone user has a low-strength EDGE connection, even a small image can take many seconds to load. Please consider moving to an asynchronous loading method.
Tim
sugar
+1  A: 

I've written RemoteImage class to load images over the network asynchronously. It also takes care of freeing the memory when necessary. See this post: http://www.dimzzy.com/blog/2009/11/remote-image-for-iphone/

dimzzy