show image from sqlite database in uiimageview - iphone

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

Related

How to display image in the simulator?

I am using sqlite database and i have stored the path of image in my sqlite file.
But now I want to display image from the path stored in sqlite file.
for that I have written following code.
image_wine.image=[[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[wineDetail objectForKey:#"wine_photo1"]]];
where image_wine is my UIImageView and
wine_photo1 is my sqlite database field where path is stored.
but I am not able to get the image on my simulator when I run the app.
plz tell me how to solve the problem.
thanx.
You are doing a very basic mistake. You should assign UIImage instance to an UIImage object, not an UIImageView instance.
image_wine.image = [UIImage imageWithContentsOfFile:[wineDetail objectForKey:#"wine_photo1"] ];
image_wine.image=[[[UIImage alloc] initWithContentsOfFile:[wineDetail objectForKey:#"wine_photo1"]] autorelease];
or
mage_wine.image=[UIImage imageWithContentsOfFile:[wineDetail objectForKey:#"wine_photo1"]];
Into an UIImageView the propriety image is rapresented by an UIImage. Apple Doc
BTW [wineDetail objectForKey:#"wine_photo1"] is a path? If the image is contained in your project you should use imageNamed:

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.

Problem! Add a .tiff image in my iOS4 app

I use Adobe Photoshop,created a .tiff image.
Then I attach this image to an UIImageView.
Code Like:
UIImage *img = [UIImage imageNamed:#"xxx.tiff"];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
[self.view addSubview:imgView];
But,the image is not completely displayed.It's very rough and lost many details!
How can I deal with it?
If you have access to Photoshop why would you choose to save a TIFF?
PNGs are the fastest and most supported image format on the iPhone, save it as a PNG instead!

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

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.