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 12-05-2010, 06:09 PM   #1 (permalink)
Banned
 
Join Date: May 2010
Location: New Jersey
Posts: 595
Chessin is on a distinguished road
Send a message via AIM to Chessin
Question Passing UIImage between views?

I am taking a picture using the camera api and I am trying to take the image I get from it and pass it to another view. Can someone please help me with this? Thanks
Chessin is offline   Reply With Quote
Old 12-05-2010, 07:41 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Chessin View Post
I am taking a picture using the camera api and I am trying to take the image I get from it and pass it to another view. Can someone please help me with this? Thanks
I just added a link to a thread on sharing data in my signature. That should give you what you need.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 12-05-2010, 08:42 PM   #3 (permalink)
Banned
 
Join Date: May 2010
Location: New Jersey
Posts: 595
Chessin is on a distinguished road
Send a message via AIM to Chessin
Default

Quote:
Originally Posted by Duncan C View Post
I just added a link to a thread on sharing data in my signature. That should give you what you need.
I already know how to share data between view controllers. I followed this tutorial: Passing data between classes Chris-Software.com

But the problem is I am trying to get the bold line in this code to be shared to another view controller.

Code:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
	
	// Dismiss the picker
	[[picker parentViewController] dismissModalViewControllerAnimated:YES];
	
	// Get the image from the result
	UIImage* image = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
	
	// Get the data for the image as a PNG
	NSData* imageData = UIImagePNGRepresentation(image);
	
	// Give a name to the file
	//	NSString* imageName = "MyImage.png";
	NSString *imageName = @"MyPic.png";
	
	// 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:imageName];
	
	// and then we write it out
	[imageData writeToFile:fullPathToFile atomically:NO];
	
	return;
}
So I am trying to take MyPic.png and pass it to another view. But I am not sure how to share an image as I have never tried it before. Hopefully you can help me, thanks!
Chessin is offline   Reply With Quote
Old 12-05-2010, 08:54 PM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Well, the bolded line is a string, not an image. So you are passing a string then.
baja_yu is offline   Reply With Quote
Old 12-05-2010, 08:55 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Chessin View Post
I already know how to share data between view controllers. I followed this tutorial: Passing data between classes Chris-Software.com

But the problem is I am trying to get the bold line in this code to be shared to another view controller.

Code:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
	
	// Dismiss the picker
	[[picker parentViewController] dismissModalViewControllerAnimated:YES];
	
	// Get the image from the result
	UIImage* image = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
	
	// Get the data for the image as a PNG
	NSData* imageData = UIImagePNGRepresentation(image);
	
	// Give a name to the file
	//	NSString* imageName = "MyImage.png";
	NSString *imageName = @"MyPic.png";
	
	// 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:imageName];
	
	// and then we write it out
	[imageData writeToFile:fullPathToFile atomically:NO];
	
	return;
}
So I am trying to take MyPic.png and pass it to another view. But I am not sure how to share an image as I have never tried it before. Hopefully you can help me, thanks!

The line you marked in bold is a string, not an image.

The method you're posting takes an image the user picks and saves it to a file in the documents directory.

What do you want to share with another view controller? The image the user selected, in memory? The path to the image file on disk? The filename of the image file?
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 12-05-2010, 08:57 PM   #6 (permalink)
Banned
 
Join Date: May 2010
Location: New Jersey
Posts: 595
Chessin is on a distinguished road
Send a message via AIM to Chessin
Default

Quote:
Originally Posted by Duncan C View Post
The line you marked in bold is a string, not an image.

The method you're posting takes an image the user picks and saves it to a file in the documents directory.

What do you want to share with another view controller? The image the user selected, in memory? The path to the image file on disk? The filename of the image file?
I want to share the string. I am trying to get it by accessing the path to the image file on disk. So the user takes a picture, I get that picture and share it to another view controller.
Chessin is offline   Reply With Quote
Old 12-05-2010, 09:03 PM   #7 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Chessin View Post
I want to share the string. I am trying to get it by accessing the path to the image file on disk. So the user takes a picture, I get that picture and share it to another view controller.


So add a new property to your second view controller, imageFileName.

@property (nonatomic, rertain) imageFileName;

In your imagePickerViewController, add code to install the image name into the second view controller:

Code:
theSecondViewController.imageFilename = myFileName;
Done.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
image between views

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: 389
7 members and 382 guests
chemistry, daudrizek, HemiMG, jeroenkeij, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

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