pulling info from a plist - iphone

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

Related

show image from sqlite database in uiimageview

I have stored image path in sqlite and I successfully fetched image path from the database. I stored it in a string. I print the path in the console which is as follows:
2012-10-26 11:54:37.888 valvolineApp[1211:207] Image path:/Users/shufflelabs/Library/Application Support/iPhone Simulator/5.0/Applications/6B6D67DB-92AB-48C5-856B-861423FB22F4/valvolineApp.app/11_fuel system service.jpg
but now how to show the respective image in the uiimageview?
I am very confusing here.
share the idea if you have
thanx...
Try this
UIImage *img = [UIImage imageWithContentsOfFile:(the file path)];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
If u still facing problem similar posts are seen below.
programmatically-show-image-in-uiimageview-iphone
dispay-image-in-uiimageview
how-to-display-images-in-imageview-in-iphone

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.

iphone image loading problem

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.

UIImages on UITableView?

what is the best method to display about 300 png images into a UITableView..
i dont wanna display them at the same time... i have 3 tableViewControllers that will each display about 100 imgaes.. (its for a catalog so the images are important to display)
i used [uiimage imageNamed:] but that method caches the images and they dont get released so the memory usage is big.... is there any way to release the cache when the nav controller pushes a different view controller?
i also tried [uiimage alloc] initWithContentsOfFile] but the images wont display....
any help?
[UIImage imageNamed:#"foo.png"];
is equivalent to
[[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"foo" ofType:#"png"]] autorelease];
except it does not cache the image.
If you write your own caching function, you can purge it at any time. When you need an image, check an NSMutableDictionary by name. If it does not exist, load the image normally and add it to the dictionary with the name as a key. To flush the cache, remove all objects from the dictionary.

Does UIImage's -imageNamed: method work for image files stored in 'Documents'?

My app downloads a small image file from a remote server and I am trying to display it along with some other small image files that are pre-installed in the app. I am using [UIImage imageNamed:#"TheImageName.png"] to get the images (see below for more detail). The pre-installed images display as expected but the image in my apps 'Documents' directory is no where to be found. Should I be using -imageNamed for an image in 'Documents' or some other method?
UIImage* documentsImage = [UIImage imageNamed:#"TheImageName.png"];
UIImageView* anImageView = [[UIimageView alloc] initWithImage:documentsImage];
[self.view addSubview:anImageView];
Ah, nevermind. I found that using [UIImage imageWithContentsOfFile:filePath] works for this. imageNamed just returns nil.
No, +imageNamed: only loads images from the app bundle.
Also, don't include the .png extension when using that class method.