Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-22-2011, 02:26 PM   #1 (permalink)
Registered Member
 
aceiswild's Avatar
 
Join Date: Oct 2011
Location: Canada
Posts: 62
aceiswild is on a distinguished road
Default Passing image from one view to another

Hey guys,
So i have an application that when you push a button it opens the camera and you can take a picture. After you take the picture you can click use and it displays the picture in the same view in a UIImageView.
What i need to do is when i click "use" i want the image to be sent to a different viewController to view the image. My problem is right now it is not displaying in my new viewController and is just showing a white screen.
I don't think i can use a UIImageView to display the image in my new viewController because once the image is sent it is programatically broken up into puzzle pieces that you can move around.
I can provide my code in advance, but would be ALOT to post here!

thanks in advance!!
Steve!
__________________
Don't be a quitter! Never give up and keep pushing to succeed at the things you love!
aceiswild is offline   Reply With Quote
Old 11-22-2011, 08:15 PM   #2 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

You can save it in your app sandbox first upon loading using NSUserDefaults. And then, in the next viewController, retrieve it back out.
rocotilos is offline   Reply With Quote
Old 11-22-2011, 08:47 PM   #3 (permalink)
Registered Member
 
aceiswild's Avatar
 
Join Date: Oct 2011
Location: Canada
Posts: 62
aceiswild is on a distinguished road
Default

Quote:
Originally Posted by rocotilos View Post
You can save it in your app sandbox first upon loading using NSUserDefaults. And then, in the next viewController, retrieve it back out.
Thanks rocotiles, I will give it a shot when I get back from the girlfriends. It sounds pretty logic and straight forward!

Steve
__________________
Don't be a quitter! Never give up and keep pushing to succeed at the things you love!
aceiswild is offline   Reply With Quote
Old 11-22-2011, 10:34 PM   #4 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

Quote:
Originally Posted by aceiswild View Post
Thanks rocotiles, I will give it a shot when I get back from the girlfriends. It sounds pretty logic and straight forward!

Steve
girlfriends

plural
rocotilos is offline   Reply With Quote
Old 11-22-2011, 11:02 PM   #5 (permalink)
Registered Member
 
aceiswild's Avatar
 
Join Date: Oct 2011
Location: Canada
Posts: 62
aceiswild is on a distinguished road
Default

Quote:
Originally Posted by rocotilos View Post
girlfriends

plural
haha nothing wrong with more then 1
She hates me working on my computer!

So i am guessing since i havnt explored to much with sandbox, when i use NSUserDefaults, i can take or select an image from my album and it will be saved in sandbox, then when i need to get that image in a different viewController, i can just call it from sandbox to retrieve the image and then use it?

Im gonna start researching this, very interesting and useful solution!

Thanks!!
__________________
Don't be a quitter! Never give up and keep pushing to succeed at the things you love!
aceiswild is offline   Reply With Quote
Old 11-23-2011, 03:56 AM   #6 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

Yes, you are right. Except I think using the app sandbox directly probably is better than using NSUserDefault's "object".

Here is a code block that I always use in my apps.

Saving:

Code:
-(void)savetheimage:(NSString *)imgname:(UIImage *)fromimage {
	
	// Now, we have to find the documents directory so we can save it
	// Note that you might want to save it elsewhere, like the cache directory,
	// or something similar.
	NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString* documentsDirectory = [paths objectAtIndex:0];
	
	// Now we get the full path to the file
	NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imgname];
	
	NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(fromimage)];
    [imageData writeToFile:fullPathToFile atomically:YES];
	
}
Usage example:

Code:
 [self savetheimage:@"myImage1.png":imageView.image];
To load just call this lines

Code:
 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 	
        NSString *uniquePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"myImage1.png"];
imageView.image = [[UIImage alloc] initWithContentsOfFile:uniquePath];
It's basically getting the full path of the image (in the sandbox), and loading it up in a UIImage using initWithContentsOfFile. Pretty simple.
rocotilos is offline   Reply With Quote
Old 11-23-2011, 09:19 AM   #7 (permalink)
Registered Member
 
aceiswild's Avatar
 
Join Date: Oct 2011
Location: Canada
Posts: 62
aceiswild is on a distinguished road
Default

Quote:
Originally Posted by rocotilos View Post
Yes, you are right. Except I think using the app sandbox directly probably is better than using NSUserDefault's "object".

Here is a code block that I always use in my apps.

Saving:

Code:
-(void)savetheimage:(NSString *)imgname:(UIImage *)fromimage {
	
	// Now, we have to find the documents directory so we can save it
	// Note that you might want to save it elsewhere, like the cache directory,
	// or something similar.
	NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString* documentsDirectory = [paths objectAtIndex:0];
	
	// Now we get the full path to the file
	NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imgname];
	
	NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(fromimage)];
    [imageData writeToFile:fullPathToFile atomically:YES];
	
}
Usage example:

Code:
 [self savetheimage:@"myImage1.png":imageView.image];
To load just call this lines

Code:
 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 	
        NSString *uniquePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"myImage1.png"];
imageView.image = [[UIImage alloc] initWithContentsOfFile:uniquePath];
It's basically getting the full path of the image (in the sandbox), and loading it up in a UIImage using initWithContentsOfFile. Pretty simple.

Thanks for the example. Wil give it a try tonight. When I take a picture or choose from album I can easily display it in a UIImageView in the current viewController but the thing is I don't think when I want to display it in my second viewController I can't use a UIimageView because that will cause the image to be static and if it's a static image I will not be able to break the image up in puzzle pieces and move them around. It would almost have to break up the image and put each broken piece in its own UIImageView programmatically.

But I will see what happens! Never know!

Thanks steve
__________________
Don't be a quitter! Never give up and keep pushing to succeed at the things you love!
aceiswild is offline   Reply With Quote
Old 11-23-2011, 11:22 AM   #8 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

Well, you are not supposed to be calling/messing with objects in another viewController from current viewcontroller anyways - cuz then it would violate the MVC pattern. if have to pass it around, use delegates (im not good at this yet), or as i explained, via a middle man (nsuserdefaults/sandbox).
rocotilos is offline   Reply With Quote
Old 11-23-2011, 11:40 AM   #9 (permalink)
Registered Member
 
aceiswild's Avatar
 
Join Date: Oct 2011
Location: Canada
Posts: 62
aceiswild is on a distinguished road
Default

Quote:
Originally Posted by rocotilos View Post
Well, you are not supposed to be calling/messing with objects in another viewController from current viewcontroller anyways - cuz then it would violate the MVC pattern. if have to pass it around, use delegates (im not good at this yet), or as i explained, via a middle man (nsuserdefaults/sandbox).
That's okay I will test with different ideas. But every bit of info I get helps !
Thanks
__________________
Don't be a quitter! Never give up and keep pushing to succeed at the things you love!
aceiswild is offline   Reply With Quote
Reply

Bookmarks

Tags
image, pass the images

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 396
16 members and 380 guests
7twenty7, chiataytuday, Clouds, dedeys78, Duncan C, e2applets, EvilElf, iekei, ipodphone, jeroenkeij, leostc, mbadegree, Murphy, QuantumDoja, sacha1996, Sami Gh
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:35 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0