开发者

Loading image from url problem iphone

I'm loading images from url into webviews but that's showing me images which are cut down. I tried doing sizeToFit, but that shows a very small image cornered at left in my webview as the webage is large and image at its upper left corner.

EDIT: This' how I'm loading images in webview. Here, expanded_photo is webview.

  NSString *urlAddress = [NSString stringWithFormat:@"%@",photo_url];   
  NSURL *url = [NSURL URLWithString:urlAddress];           
  NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];            
  [expanded_photo loadRequest:requestObj];                  

Whenever I try l开发者_如何学Coading it through uiimageview using a uiimage like following, Here expanded_photo is imageview which I'm creating in a nib file:

UIImage *image1 = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:photo_url]]];
expanded_photo.image = image1;

This takes a lot of time to load.

I want a solution which can load image from url in a small amount of time and the image is not cut.

Can anybody please help?

Thanx in advance.


Be aware that -[NSData dataWithContentsOfURL:] loads the data synchronously and thus blocks your main thread until the download is finished. When you load multiple images that way, all those loading operations are executed sequentially. This is not only slow but also your app is unresponsive during loading.

You might consider moving the actual load request in a background thread (using NSOperationQueue) or use NSURLConnection to asynchronously load the image.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜