2009-08-06 31 views
0
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]; 
    } 

iPhone中的图像加载问题? - 来自webservice


我已经将图像载入 imgBiteSpot。 图像从web服务加载。问题是它需要太多时间(35秒到1分钟)。

如果我删除图像 - >代码/加载,反应时间仅为0.2秒。

减少图像加载过程的时间的解决方案是什么?

在此先感谢您的帮助。

回答

3

您正在使用NSData的方法dataWithContentsOfURL:,它从服务器同步加载数据,从而阻塞线程直到接收到图像。

你应该做的是将空白或“加载”图像加载到你的UIImage中,然后使用NSURLConnection异步下载图像并在完成时显示它。请参阅NSURLConnection参考文献和URL Loading System文档。