iphone image loading problem - iphone

I have make a one small image and in which one detail page is there.
and I in detail page I have one image tag which is in webview with html page.
It's work completely but image take a much time for loading and show in the screen.
So how can I reduce the time of loading for image. and this image is come form url.

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];
}

You could consider not downloading the image but downloading a one characters variable/flag from a web service. Depending on the answer from the web service you could load an image locally from the bundle? This could be faster.
Chris.

This is best example for loading image.
http://www.dimzzy.com/blog/2009/11/remote-image-for-iphone/

Its take time base on image size and internet speed.
But one thing you can do in your application.
You can download asynchronously that image and store it in temporary variable before you go in detail image view. When you go on that detail image you can load that downloaded image as per your requirement.

Related

Loading Images From A URL(nsurlconnection)

I have to Implement a UITableView that should display all hosted photos. Load the photos synchronously and asynchronously in different tabs.
how to call images from url??
To load an image from a url:
NSData *imageData = [NSData dataWithContentsOfURL:yourURL];
UIImage *image = [UIImage imageWithData:imageData];
You can use GCD to perform the actions asynchronously. There's a good tutorial of almost exactly what you're trying to achieve here
You can used the Apple TableView Lazy Loading. They have sample codes that download images asynchonously to avoid freeze of UI. See link below
Apple LazyTableImages

UIImage display differently when saving and loading from file

I'm download jpeg picture from web server and load it to UIImage.
If I display the UIImage in UIImageView directly, I see the picture correctly.
But if i cache the image to file with :
[UIImageJPEGRepresentation(image,1.0f) writeToFile:sFilePath atoimcally:YES]
and load it with :
image=[UIImage imageWithContentsOFile:sFilePath]
and display this in the same UIImageView, I can see white stripes in the sides of the picture.
again, Exactly the same UIImageView object with the same properties settings in it.
Why is that?
You can simply write to a file the NSData you have loaded from the web, without going through the UIImageJPEGRepresentation routine.
[dataObject writeToURL:fileURL atomically:YES];
and to retrieve
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[fileURL path]];
That works really well in my app.

large image size problems

I am loading images of size 1800x1300 in UIImage.(getting the images from server..)then i am adding that images into Uiscrollview.while scrolling my images ,the app getting crashed.is it a the image size issue.....?thanks in advance.
UIImage *image = [UIImage imageNamed:#"image.png"];
NSData *imgData = UIImageJPEGRepresentation([UIImage imageWithCGImage:[image CGImage]],0.5);
UIImage *compressedImage = [UIImage imageWithData:mgData];
You should definitely scale your images down, significantly, especially for the iPhone screen size.
You should also compress your images as much as you can without affecting the quality. Your image, I am assuming is somewhere around 1.5MB - 2MB, so that will use up an extreme amount if memory, and cause your device to crash every time.

What is the best way to display thumbnail list in UITableview

I have an app that need to display image(in a folder) thumbnail list in UITableView.
My way is to create the thumbnail of an image when add the image to the folder.
CGSize itemSize = CGSizeMake(100, 100);
UIGraphicsBeginImageContext(itemSize);
[image drawInRect:CGRectMake(0, 0,100, 100)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData* imageData1 =[NSData dataWithData:UIImagePNGRepresentation (image)];
NSMutableString *sss1=[[NSMutableString alloc] initWithString:folderPath];
[sss1 appendString: thumbnailIdString] ;
[sss1 appendString:fileName] ;
[imageData1 writeToFile:sss1 atomically:NO];
[sss1 release];
Then the app display the resized the thumbnail image in UITableView.
It DOES work. But the performance is not perfect.
It needs to load the large image and rewrites the thumbnails to the folder.
Is there any other better solution? I checked Three20, but I am not sure if it can do this.
Welcome any comment
Thanks
interdev
You can load and resize image in a worker thread, and when the image is ready, show this image in the main thread. In order to complete the above behaviors, you need to find a thread-safe way to resize image. The UIGraphicsBeginImageContext() and UIGraphicsEndImageContext() should only run in the main thread.

pulling info from a plist

I'm able to pull information from a plist using:
nameTextField.text = [recipe objectForKey:NAME_KEY];
ingredientsText.text = [ingredients objectForKey:NAME_KEY];
I also have images in the plist [the names of the images, not the image data]
does anyone know how i would display an image in a similar manner?
thanks in advance.
You'll have to create an image with the contents of the file at the stored path. Either use imageWithContentsOfFile: or imageNamed:, where imageNamed: takes only the filename and caches images, useful for images that are small and appear often in the UI. Also note, that imageNamed: searches for a #2x-Version of the image in iOS4.
imageWithContentsOfFile takes a full path including your app-bundle's path and dose not have a cache. It's intended for larger images that only appear once on a screen.
imageView.image = [UIImage imageNamed:[recipe objectForKey:IMAGE_KEY]];
imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:[recipe objectForKey:IMAGE_KEY] ofType:nil]];