get image from previous controller - iphone

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

Related

GIF animations in UIImageView in Swift

How am I able to automatically load and run a GIF using UIImageView?
I have imported each image individually but now sure where to go from here.
Also it is to be executed in viewDidLoad, not by using an IBAction of any kind.
I don't know if UIImageView supports gif format but you can give bunch of image to UIImageView and it shows them in order. Here is how:
let imageView = UIImageView()
imageView.animationImages = imageArray // imageArray is array of UIImage instances
There is bunch of other properties and methods that control this behavior in UIImageView. You can find more information in documentation

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

Summoning stored images

I have images in my iphone application I would like to summon when needed.
The idea is when the user takes a photo and it's loaded on the imageview, he or she will be able to call out my custom images that's preloaded in the app. The user can then move the custom image around their original photo.
My question is, how do I implement that? How do I store custom image for the user to call out later on?
Thanks.
So you have image files imported into your project and you'd like to show them on-screen?
Say you want to display the image "paintcan.jpg". All you have to do is create an image view, set its image, and add it to the main view.
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)] autorelease];
imageView.image = [UIImage imageNamed:#"paintcan"];
[self.view addSubview:imageView];

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:

UIButton with image losing its newly set image

I've got a UIButton (custom, with image) set up in IB which is an IBOutlet in my code.
In my viewDidLoad method in the viewController, I am trying to change the existing image of the UIButton
UIImage *newbuttonimage = [UIImage imageNamed:#"newbuttonimage.png"];
testbutton.imageView.image = newbuttonimage;
OK, that works when starting the app, but whenever you interact with the button (press it), it changes to the original image (set in IB). There's no other code to change images in the whole project, so what is going on?
Incidentally, when I put the above code in any other part of my project it doesn't change the image.
You should try using setImage:forState instead of assigning the image directly; there are multiple states of a UIButton and, if not set properly, may yield unwanted behaviors (akin to the ones you're seeing).
Doh! I should have used this code instead:
UIImage *newbuttonimage = [UIImage imageNamed:#"newbuttonimage.png"];
[testbutton setImage:newbuttonimage forState:UIControlStateNormal];