How to display image in the simulator? - iphone

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:

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.

problem with Image in custom Cell

Getting image data from sqlite database but not able to display in custom cell of imageview.is there any conversion of image data into image.
Super easy. There's a UIImage convenience method for exactly that.
//assuming the existence of an NSData *myData
UIImage *myImage = [UIImage imageWithData:myData];
So easy, in fact, I suspect that's not actually your question. If not, please clarify what you're asking.

get image from previous controller

i am getting a picture from the iPhone's camera in one nib file (getPhoto.xib), where I save it into the camera library and also display it in an UIImageView (image1). Then, I have a next button which loads a different nib file (naming.nib) where the user can add a name for the image. How I can access the image from the first nib file so that I can display it in an UIImageView (image2) in the second nib file?
I'm trying the following, but nothing is displayed in image2:
UIImageView *image2= [[UIImageView alloc initWithImage:
[UIImageView imageNamed:image1]];
the imageNamed: method requires an NSString argument. Assuming that the name of image1 is actually "image1", you would do:
UIImageView *image2 = [[UIImageView alloc]
initWithImage:[UIImageView imageNamed:#"image1"]];
Note that the "name" here is the name you used when saving the image to the camera library.
call retain on image1 (the one you get from camera) and use it where ever u are currently trying to use image2

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.