views:

70

answers:

1

Hi all,

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 loading 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.

A: 

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.

Ortwin Gentz
Thanx Ortwin for your response. Currently, I want to show this image on main thread only, but time taken is my concern right now. I also dont want clipped images which are shown by webview.
neha
Can you be more specific where you loose the time? Is the actual fetching taking the time or the image decoding? Does this happen for different image URLs so can you omit an issue on the server side?Are you loading just one image?
Ortwin Gentz
At one time, I'm loading only one image. Images are not taking so much time when loaded in webview but when I'm using -[NSData dataWithContentsOfURL:] it's taking a lot of time.. That's why I guess decoding is taking so much time..
neha
It shouldn't. I'd split up the code and measure how long the individual operations take.
Ortwin Gentz